Building user posts object after fetching user to ensure user fetched posts and directly fetched posts are added to the same user key. Refactor to make better use of functions. Moved profile detail saving call to content fetch. No longer attempting and failing to save profile details for deleted users (directory would not exist).

This commit is contained in:
2018-06-17 01:11:10 +02:00
parent 3b5d886da3
commit 7cf1a99915
11 changed files with 199 additions and 157 deletions

View File

@@ -9,7 +9,7 @@ const textToStream = require('./textToStream.js');
const save = require('./save.js');
function saveProfileDetails(user) {
if(config.library.profile.image && !user.fallback) {
if(config.library.profile.image && !user.fallback && !user.deleted) {
const image = user.profile ? user.profile.image : user.image;
if(config.library.profile.avoidAvatar && new urlPattern('http(s)\\://(www.)redditstatic.com/avatars/:id(.:ext)(?:query)').match(image)) {
@@ -26,7 +26,7 @@ function saveProfileDetails(user) {
}
}
if(config.library.profile.description && !user.fallback) {
if(config.library.profile.description && !user.fallback && !user.deleted) {
if(user.profile && user.profile.description) {
const filepath = interpolate(config.library.profile.description, user);
const stream = textToStream(user.profile.description);

20
src/save/writeToIndex.js Normal file
View File

@@ -0,0 +1,20 @@
'use strict';
const config = require('config');
const fs = require('fs-extra');
const Promise = require('bluebird');
const csvStringify = Promise.promisify(require('csv').stringify);
const interpolate = require('../interpolate.js');
async function writeToIndex(posts, user) {
const filename = interpolate(config.library.index.file, user, null, false);
const data = posts.map(post => config.library.index.keys.map(key => interpolate(`$${key}`, user, post, null, false, 'YYYY-MM-DDTHH:mm:ssZ')));
const tsvString = await csvStringify(data, { delimiter: '\t', header: true, columns: config.library.index.keys });
return fs.writeFile(filename, tsvString);
}
module.exports = writeToIndex;