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