Dealing with users without profile.
This commit is contained in:
parent
4c574ef43c
commit
8aca700269
|
@ -3,13 +3,18 @@
|
|||
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,
|
||||
};
|
||||
|
||||
if(user.subreddit) {
|
||||
Object.assign(curatedUser, {
|
||||
profile: {
|
||||
id: user.subreddit.display_name.name,
|
||||
title: user.subreddit.display_name.title,
|
||||
|
@ -18,7 +23,10 @@ function curateUser(user) {
|
|||
description: user.subreddit.display_name.public_description,
|
||||
over18: user.subreddit.display_name.over_18
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return curatedUser;
|
||||
};
|
||||
|
||||
module.exports = curateUser;
|
||||
|
|
|
@ -29,12 +29,17 @@ 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 : '',
|
||||
});
|
||||
|
||||
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) {
|
||||
Object.assign(vars, {
|
||||
|
|
|
@ -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