ripunzel/methods/imgurAlbum.js

39 lines
1.1 KiB
JavaScript

'use strict';
const note = require('note-log');
const util = require('util');
const config = require('config');
const fetch = require('node-fetch');
function imgurAlbum(post) {
return fetch(`https://api.imgur.com/3/album/${post.host.id}`, {
headers: {
'Authorization': `Client-ID ${config.methods.imgur.clientId}`
}
}).then(res => res.json()).then(res => {
return {
album: {
id: res.data.id,
url: res.data.link,
title: res.data.title,
description: res.data.description,
datetime: res.data.datetime * 1000,
original: res.data
},
items: res.data.images.map(item => ({
id: item.id,
url: item.link,
title: item.title,
description: item.description,
datetime: item.datetime * 1000,
type: item.type,
original: item
}))
};
}).catch(error => {
note(error);
});
};
module.exports = imgurAlbum;