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

This commit is contained in:
DebaucheryLibrarian 2024-09-11 05:16:56 +02:00
parent e48892126f
commit b05ae06b00
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}`);
const data = await res.json();
if (data.error) {
throw new Error(data.error);
}
return { return {
album: null, album: null,
items: [{ items: [{
id: res.gfyItem.gfyName, id: data.gfyItem.gfyName,
url: res.gfyItem.webmUrl, url: data.gfyItem.webmUrl,
title: res.gfyItem.title, title: data.gfyItem.title,
description: res.gfyItem.description, description: data.gfyItem.description,
type: 'video/webm', type: 'video/webm',
datetime: new Date(res.gfyItem.createDate * 1000), datetime: new Date(data.gfyItem.createDate * 1000),
original: res.gfyItem original: data.gfyItem,
}] }],
};
}).catch(error => {
console.error(error);
});
}; };
}
module.exports = gfycat; module.exports = gfycat;

View File

@ -10,7 +10,8 @@ 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) => {
const entryPost = {
id: post.id, id: post.id,
subreddit: post.subreddit, subreddit: post.subreddit,
permalink: post.permalink, permalink: post.permalink,
@ -19,7 +20,14 @@ async function writeToIndex(posts, profilePaths, user) {
date: post.datetime, date: post.datetime,
indexed: now, indexed: now,
title: post.title, title: post.title,
})); };
if (post.previewFallback) {
entryPost.preview = true;
}
return entryPost;
});
const data = { const data = {
profile: { profile: {