Dealing with users without profile.
This commit is contained in:
parent
c3355200dd
commit
94e1575c30
|
@ -3,22 +3,30 @@
|
|||
const path = require('path');
|
||||
|
||||
function curateUser(user) {
|
||||
return {
|
||||
const curatedUser = {
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
created: new Date(user.created_utc * 1000),
|
||||
image: user.icon_img,
|
||||
gold: user.is_gold,
|
||||
verified: user.verified,
|
||||
verifiedEmail: user.has_verified_email,
|
||||
profile: {
|
||||
id: user.subreddit.display_name.name,
|
||||
title: user.subreddit.display_name.title,
|
||||
image: user.subreddit.display_name.icon_img,
|
||||
banner: user.subreddit.display_name.banner_img,
|
||||
description: user.subreddit.display_name.public_description,
|
||||
over18: user.subreddit.display_name.over_18
|
||||
}
|
||||
};
|
||||
|
||||
if(user.subreddit) {
|
||||
Object.assign(curatedUser, {
|
||||
profile: {
|
||||
id: user.subreddit.display_name.name,
|
||||
title: user.subreddit.display_name.title,
|
||||
image: user.subreddit.display_name.icon_img,
|
||||
banner: user.subreddit.display_name.banner_img,
|
||||
description: user.subreddit.display_name.public_description,
|
||||
over18: user.subreddit.display_name.over_18
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return curatedUser;
|
||||
};
|
||||
|
||||
module.exports = curateUser;
|
||||
|
|
|
@ -29,11 +29,16 @@ function interpolate(pattern, user, post, item) {
|
|||
$userVerified: user.verified ? config.library.booleans.verified : '',
|
||||
$userVerifiedEmail: user.verifiedEmail ? config.library.booleans.verifiedEmail : '',
|
||||
$userGold: user.gold ? config.library.booleans.gold : '',
|
||||
$profileId: user.profile.id,
|
||||
$profileTitle: user.profile.title,
|
||||
$profileDescription: user.profile.description,
|
||||
$profileOver18: user.profile.over18 ? config.library.booleans.over18 : ''
|
||||
});
|
||||
|
||||
if(user.profile) {
|
||||
Object.assign(vars, {
|
||||
$profileId: user.profile.id,
|
||||
$profileTitle: user.profile.title,
|
||||
$profileDescription: user.profile.description,
|
||||
$profileOver18: user.profile.over18 ? config.library.booleans.over18 : ''
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if(post) {
|
||||
|
|
|
@ -9,18 +9,20 @@ const save = require('./save.js');
|
|||
|
||||
function saveProfileDetails(user) {
|
||||
if(config.library.profile.image) {
|
||||
const image = user.profile ? user.profile.image : user.image;
|
||||
|
||||
const filepath = interpolate(config.library.profile.image, user, null, {
|
||||
// pass profile image as item to interpolate extension variable
|
||||
url: user.profile.image
|
||||
url: image
|
||||
});
|
||||
|
||||
fetchItem(user.profile.image).then(stream => save(filepath, stream)).catch(error => {
|
||||
fetchItem(image).then(stream => save(filepath, stream)).catch(error => {
|
||||
console.log('\x1b[33m%s\x1b[0m', `Could not save profile image for '${user.name}': ${error}`);
|
||||
});
|
||||
}
|
||||
|
||||
if(config.library.profile.description) {
|
||||
if(user.profile.description) {
|
||||
if(user.profile && user.profile.description) {
|
||||
const filepath = interpolate(config.library.profile.description, user);
|
||||
const stream = textToStream(user.profile.description);
|
||||
|
||||
|
|
Loading…
Reference in New Issue