Added support for fetching content directly from host. Improved pattern interpolation. Refactored content modules.

This commit is contained in:
2024-09-11 05:16:57 +02:00
parent 20cb522689
commit b9a7e4b83a
26 changed files with 572 additions and 440 deletions
+30 -34
View File
@@ -1,42 +1,38 @@
'use strict';
'use strict';
const util = require('util');
const config = require('config');
const fetch = require('node-fetch');
function eroshareAlbum(post) {
return fetch(`https://web.archive.org/web/20170630040157im_/https://eroshare.com/${post.host.id}`).then(res => {
if(res.ok) {
return res.text();
}
async function eroshareAlbum(host) {
const res = await fetch(`https://web.archive.org/web/20170630040157im_/https://eroshare.com/${host.id}`);
return Promise.reject(`Unable to recover Eroshare album or item '${post.host.id}' :(`);
}).then(res => {
const data = JSON.parse(res.match(/var album = .*/)[0].slice(12, -1));
const extract = config.library.album.extractSingleItem && data.items.length === 1;
if (!res.ok) {
throw new Error(`Unable to recover Eroshare album or item '${host.id}' :(`);
}
return {
album: extract ? null : {
id: data.slug,
title: data.title,
datetime: new Date(data.created_at)
},
items: data.items.map(item => {
return {
extracted: extract,
id: item.slug,
url: item.type === 'Image' ? item.url_full_protocol : item.url_mp4,
title: data.title,
description: item.description,
type: item.type === 'Image' ? 'image/jpeg' : 'video/mp4',
datetime: new Date(data.created_at),
width: data.width,
height: data.height,
original: item
};
})
};
});
};
const html = await res.text();
const data = JSON.parse(html.match(/var album = .*/)[0].slice(12, -1));
const extract = config.library.extractSingleAlbumItem && data.items.length === 1;
return {
album: extract ? null : {
id: data.slug,
title: data.title,
datetime: new Date(data.created_at),
},
items: data.items.map(item => ({
extracted: extract,
id: item.slug,
url: item.type === 'Image' ? item.url_full_protocol : item.url_mp4,
title: data.title,
description: item.description,
type: item.type === 'Image' ? 'image/jpeg' : 'video/mp4',
datetime: new Date(data.created_at),
width: data.width,
height: data.height,
original: item,
})),
};
}
module.exports = eroshareAlbum;