Improved missing gfycat handling. Added 'preview' marker to index.

This commit is contained in:
ThePendulum 2018-07-02 23:15:06 +02:00
parent dfee2c2ae2
commit 5dce74588b
3 changed files with 41 additions and 32 deletions

View File

@ -21,7 +21,7 @@ const attachContentInfo = users => {
if(config.fetch.archives.preview && post.preview) { if(config.fetch.archives.preview && post.preview) {
console.log(`Found preview images for unavailable source '${post.url}' (${post.permalink})`); console.log(`Found preview images for unavailable source '${post.url}' (${post.permalink})`);
return [...accPosts, {...post, content: await methods.redditPreview(post)}]; return [...accPosts, {...post, previewFallback: true, content: await methods.redditPreview(post)}];
} }
return accPosts; return accPosts;

View File

@ -1,26 +1,27 @@
'use strict'; 'use strict';
const util = require('util');
const config = require('config');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
function gfycat(post) { async function gfycat(post) {
return fetch(`https://gfycat.com/cajax/get/${post.host.id}`).then(res => res.json()).then(res => { const res = await fetch(`https://gfycat.com/cajax/get/${post.host.id}`);
return { const data = await res.json();
album: null,
items: [{ if (data.error) {
id: res.gfyItem.gfyName, throw new Error(data.error);
url: res.gfyItem.webmUrl, }
title: res.gfyItem.title,
description: res.gfyItem.description, return {
type: 'video/webm', album: null,
datetime: new Date(res.gfyItem.createDate * 1000), items: [{
original: res.gfyItem id: data.gfyItem.gfyName,
}] url: data.gfyItem.webmUrl,
}; title: data.gfyItem.title,
}).catch(error => { description: data.gfyItem.description,
console.error(error); type: 'video/webm',
}); datetime: new Date(data.gfyItem.createDate * 1000),
}; original: data.gfyItem,
}],
};
}
module.exports = gfycat; module.exports = gfycat;

View File

@ -10,16 +10,24 @@ async function writeToIndex(posts, profilePaths, user) {
const filename = interpolate(config.library.index.file, user, null, false); const filename = interpolate(config.library.index.file, user, null, false);
const now = new Date(); const now = new Date();
const newAndUpdatedEntries = posts.concat(user.indexed.updated).map(post => ({ const newAndUpdatedEntries = posts.concat(user.indexed.updated).map((post) => {
id: post.id, const entryPost = {
subreddit: post.subreddit, id: post.id,
permalink: post.permalink, subreddit: post.subreddit,
url: post.url, permalink: post.permalink,
hostId: post.host.id, url: post.url,
date: post.datetime, hostId: post.host.id,
indexed: now, date: post.datetime,
title: post.title, indexed: now,
})); title: post.title,
};
if (post.previewFallback) {
entryPost.preview = true;
}
return entryPost;
});
const data = { const data = {
profile: { profile: {