39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
|
'use strict';
|
||
|
|
||
|
const config = require('config');
|
||
|
|
||
|
const interpolate = require('../interpolate.js');
|
||
|
const fetchItem = require('../fetch/item.js');
|
||
|
const textToStream = require('./textToStream.js');
|
||
|
const save = require('./save.js');
|
||
|
|
||
|
function saveProfileDetails(user) {
|
||
|
if(config.library.profile.image) {
|
||
|
const filepath = interpolate(config.library.profile.image, user, null, {
|
||
|
// pass profile image as item to interpolate extension variable
|
||
|
url: user.profile.image
|
||
|
});
|
||
|
|
||
|
fetchItem(user.profile.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) {
|
||
|
const filepath = interpolate(config.library.profile.description, user);
|
||
|
const stream = textToStream(user.profile.description);
|
||
|
|
||
|
save(filepath, stream).catch(error => {
|
||
|
console.log('\x1b[33m%s\x1b[0m', `Could not save profile description for '${user.name}': ${error}`);
|
||
|
});
|
||
|
} else {
|
||
|
console.log('\x1b[33m%s\x1b[0m', `No profile description for '${user.name}'`);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return user;
|
||
|
};
|
||
|
|
||
|
module.exports = saveProfileDetails;
|