Fixed index file for single post fetching.
This commit is contained in:
parent
cdd5ed36bf
commit
99c7d143f7
|
@ -19,7 +19,11 @@ const getPosts = require('./sources/getPosts.js')(reddit, args);
|
||||||
const getUserPosts = require('./sources/getUserPosts.js')(reddit, args);
|
const getUserPosts = require('./sources/getUserPosts.js')(reddit, args);
|
||||||
|
|
||||||
async function getCompleteUserPosts() {
|
async function getCompleteUserPosts() {
|
||||||
let userPosts = await getUserPosts(args.users);
|
let userPosts = {};
|
||||||
|
|
||||||
|
if (args.users) {
|
||||||
|
userPosts = await getUserPosts(args.users);
|
||||||
|
}
|
||||||
|
|
||||||
if (args.posts) {
|
if (args.posts) {
|
||||||
userPosts = await getPosts(args.posts, userPosts);
|
userPosts = await getPosts(args.posts, userPosts);
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
function curateUser(user) {
|
function curateUser(user) {
|
||||||
const curatedUser = {
|
const curatedUser = {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
|
|
|
@ -7,6 +7,8 @@ const ffmpeg = require('fluent-ffmpeg');
|
||||||
|
|
||||||
function save(requestedFilepath, streams, item, post) {
|
function save(requestedFilepath, streams, item, post) {
|
||||||
const filepath = requestedFilepath.split('/').map(component => {
|
const filepath = requestedFilepath.split('/').map(component => {
|
||||||
|
console.log(component);
|
||||||
|
|
||||||
if(config.library.truncate && component.length > config.library.truncate.limit) {
|
if(config.library.truncate && component.length > config.library.truncate.limit) {
|
||||||
return component.slice(0, config.library.truncate.limit - config.library.truncate.truncator.length) + config.library.truncate.truncator;
|
return component.slice(0, config.library.truncate.limit - config.library.truncate.truncator.length) + config.library.truncate.truncator;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +16,8 @@ function save(requestedFilepath, streams, item, post) {
|
||||||
return component;
|
return component;
|
||||||
}).join(path.sep);
|
}).join(path.sep);
|
||||||
|
|
||||||
|
console.log(filepath);
|
||||||
|
|
||||||
const pathComponents = path.parse(filepath);
|
const pathComponents = path.parse(filepath);
|
||||||
|
|
||||||
// allow for single stream argument
|
// allow for single stream argument
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const config = require('config');
|
||||||
|
const fs = require('fs-extra');
|
||||||
|
const yaml = require('js-yaml');
|
||||||
|
|
||||||
|
const interpolate = require('../interpolate.js');
|
||||||
|
|
||||||
|
async function getIndexedPosts(user) {
|
||||||
|
const indexFilePath = interpolate(config.library.index.file, user, null, null, false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const indexFile = await fs.readFile(indexFilePath, 'utf8');
|
||||||
|
|
||||||
|
return yaml.safeLoad(indexFile);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('\x1b[33m%s\x1b[0m', `Could not load index file for '${user.name}' at '${indexFilePath}': ${error}`);
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getIndexedPosts;
|
|
@ -1,10 +1,9 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Promise = require('bluebird');
|
const Promise = require('bluebird');
|
||||||
const config = require('config');
|
|
||||||
|
|
||||||
|
const getIndexedPosts = require('./getIndexedPosts.js');
|
||||||
const curateUser = require('../curate/user.js');
|
const curateUser = require('../curate/user.js');
|
||||||
const saveProfileDetails = require('../save/profileDetails.js');
|
|
||||||
|
|
||||||
const getUser = async (username, reddit) => {
|
const getUser = async (username, reddit) => {
|
||||||
try {
|
try {
|
||||||
|
@ -16,13 +15,12 @@ const getUser = async (username, reddit) => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: username,
|
name: username,
|
||||||
fallback: true
|
fallback: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getPostsWrap = (reddit, args) => {
|
const getPostsWrap = reddit => function getPosts(postIds, userPosts = {}) {
|
||||||
return function getPosts(postIds, userPosts = {}) {
|
|
||||||
return Promise.reduce(postIds, (accUserPosts, postId) => Promise.resolve().then(async () => {
|
return Promise.reduce(postIds, (accUserPosts, postId) => Promise.resolve().then(async () => {
|
||||||
const post = await reddit.getSubmission(postId).fetch();
|
const post = await reddit.getSubmission(postId).fetch();
|
||||||
|
|
||||||
|
@ -40,10 +38,10 @@ const getPostsWrap = (reddit, args) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await getUser(post.author.name, reddit);
|
const user = await getUser(post.author.name, reddit);
|
||||||
|
const indexed = await getIndexedPosts(user);
|
||||||
|
|
||||||
return {...accUserPosts, [post.author.name]: {...user, posts: [post]}}
|
return { ...accUserPosts, [post.author.name]: { ...user, posts: [post], indexed: { original: indexed, updated: [] } } };
|
||||||
}), userPosts);
|
}), userPosts);
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = getPostsWrap;
|
module.exports = getPostsWrap;
|
||||||
|
|
|
@ -5,6 +5,7 @@ const Promise = require('bluebird');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
|
|
||||||
|
const getIndexedPosts = require('./getIndexedPosts.js');
|
||||||
const getArchivePostIds = require('../archives/getArchivePostIds.js');
|
const getArchivePostIds = require('../archives/getArchivePostIds.js');
|
||||||
const curateUser = require('../curate/user.js');
|
const curateUser = require('../curate/user.js');
|
||||||
const interpolate = require('../interpolate.js');
|
const interpolate = require('../interpolate.js');
|
||||||
|
@ -45,20 +46,6 @@ async function getArchivedPosts(username, posts, reddit) {
|
||||||
return Promise.all(postIds.map(postId => reddit.getSubmission(postId).fetch()));
|
return Promise.all(postIds.map(postId => reddit.getSubmission(postId).fetch()));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getIndexedPosts(user) {
|
|
||||||
const indexFilePath = interpolate(config.library.index.file, user, null, null, false);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const indexFile = await fs.readFile(indexFilePath, 'utf8');
|
|
||||||
|
|
||||||
return yaml.safeLoad(indexFile);
|
|
||||||
} catch (error) {
|
|
||||||
console.log('\x1b[33m%s\x1b[0m', `Could not load index file for '${user.name}' at '${indexFilePath}': ${error}`);
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getUserPostsWrap(reddit, args) {
|
function getUserPostsWrap(reddit, args) {
|
||||||
return async function getUserPosts(usernames) {
|
return async function getUserPosts(usernames) {
|
||||||
const users = await Promise.map(usernames, async (username) => {
|
const users = await Promise.map(usernames, async (username) => {
|
||||||
|
|
Loading…
Reference in New Issue