'use strict'; const fetch = require('node-fetch'); async function imgurImage(post) { const res = await fetch(`https://imgur.com/${post.host.id}`); const html = await res.text(); if (res.status !== 200) { throw new Error(`Could not fetch info for imgur image '${post.host.id}': '${res.statusText}'`); } const dataString = html.replace(/\s+/g, ' ').match(/}}, item:(.*)}; var PREBID_TIMEOUT/)[1]; const data = JSON.parse(dataString); return { 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), }], }; } module.exports = imgurImage;