2024-09-11 03:16:56 +00:00
|
|
|
'use strict';
|
2024-09-11 03:16:53 +00:00
|
|
|
|
|
|
|
const fetch = require('node-fetch');
|
|
|
|
|
2024-09-11 03:16:56 +00:00
|
|
|
async function imgurImage(post) {
|
|
|
|
const res = await fetch(`https://imgur.com/${post.host.id}`);
|
|
|
|
const html = await res.text();
|
2024-09-11 03:16:54 +00:00
|
|
|
|
2024-09-11 03:16:56 +00:00
|
|
|
if (res.status !== 200) {
|
2024-09-11 03:16:56 +00:00
|
|
|
throw new Error(`Could not fetch info for imgur image '${post.host.id}': '${res.statusText}'`);
|
2024-09-11 03:16:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1];
|
|
|
|
const data = JSON.parse(dataString);
|
|
|
|
|
2024-09-11 03:16:56 +00:00
|
|
|
return {
|
2024-09-11 03:16:56 +00:00
|
|
|
album: null,
|
|
|
|
items: [{
|
|
|
|
id: data.hash,
|
|
|
|
url: data.animated ? `https://i.imgur.com/${post.host.id}.mp4` : `https://i.imgur.com/${post.host.id}${data.ext}`,
|
|
|
|
title: data.title,
|
|
|
|
description: data.description,
|
|
|
|
type: data.animated ? 'video/mp4' : data.mimetype,
|
|
|
|
datetime: new Date(data.timestamp || data.datetime),
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
}
|
2024-09-11 03:16:53 +00:00
|
|
|
|
|
|
|
module.exports = imgurImage;
|