2024-09-11 03:16:56 +00:00
|
|
|
'use strict';
|
2024-09-11 03:16:53 +00:00
|
|
|
|
2024-09-11 03:16:57 +00:00
|
|
|
const config = require('config');
|
2024-09-11 03:16:53 +00:00
|
|
|
const fetch = require('node-fetch');
|
|
|
|
|
2024-09-11 03:16:57 +00:00
|
|
|
async function imgurImageApi(host) {
|
|
|
|
const res = await fetch(`https://api.imgur.com/3/image/${host.id}`, {
|
2024-09-11 03:16:57 +00:00
|
|
|
headers: {
|
|
|
|
Authorization: `Client-ID ${config.methods.imgur.clientId}`,
|
|
|
|
},
|
|
|
|
});
|
2024-09-11 03:16:57 +00:00
|
|
|
|
2024-09-11 03:16:58 +00:00
|
|
|
if (res.status !== 200) {
|
|
|
|
throw new Error(`Imgur API returned HTTP ${res.status} for source '${host.url}'`);
|
|
|
|
}
|
|
|
|
|
2024-09-11 03:16:57 +00:00
|
|
|
const { data } = await res.json();
|
|
|
|
|
|
|
|
if (res.status !== 200) {
|
2024-09-11 03:16:58 +00:00
|
|
|
throw new Error(`Could not fetch info for imgur image '${host.id}': ${data.error}`);
|
2024-09-11 03:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
album: null,
|
|
|
|
items: [{
|
|
|
|
id: data.id,
|
|
|
|
url: data.animated ? data.mp4 : data.link,
|
|
|
|
title: data.title,
|
|
|
|
description: data.description,
|
|
|
|
type: data.animated ? 'video/mp4' : data.type,
|
|
|
|
datetime: new Date(data.datetime * 1000),
|
|
|
|
original: data,
|
|
|
|
}],
|
|
|
|
};
|
2024-09-11 03:16:57 +00:00
|
|
|
}
|
2024-09-11 03:16:56 +00:00
|
|
|
|
2024-09-11 03:16:57 +00:00
|
|
|
async function imgurImage(host, post) {
|
|
|
|
return imgurImageApi(host, post);
|
2024-09-11 03:16:56 +00:00
|
|
|
}
|
2024-09-11 03:16:53 +00:00
|
|
|
|
|
|
|
module.exports = imgurImage;
|