2018-04-15 02:51:02 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
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 => {
|
2018-04-20 02:40:37 +00:00
|
|
|
const extract = config.patterns.album.extractSingleItem && res.data.images.length === 1;
|
|
|
|
|
2018-04-15 02:51:02 +00:00
|
|
|
return {
|
2018-04-20 02:40:37 +00:00
|
|
|
album: extract ? null : {
|
2018-04-15 02:51:02 +00:00
|
|
|
id: res.data.id,
|
|
|
|
url: res.data.link,
|
|
|
|
title: res.data.title,
|
|
|
|
description: res.data.description,
|
2018-04-20 00:23:02 +00:00
|
|
|
datetime: new Date(res.data.datetime * 1000),
|
2018-04-15 02:51:02 +00:00
|
|
|
original: res.data
|
|
|
|
},
|
|
|
|
items: res.data.images.map(item => ({
|
2018-04-20 02:40:37 +00:00
|
|
|
extracted: extract,
|
2018-04-15 02:51:02 +00:00
|
|
|
id: item.id,
|
2018-04-20 00:23:02 +00:00
|
|
|
url: item.animated ? item.mp4 : item.link,
|
2018-04-20 02:40:37 +00:00
|
|
|
title: item.title || (extract ? res.data.title : null),
|
|
|
|
description: item.description || (extract ? res.data.description : null),
|
2018-04-20 00:23:02 +00:00
|
|
|
type: item.animated ? 'video/mp4' : item.type,
|
2018-04-16 21:46:39 +00:00
|
|
|
datetime: item.datetime * 1000,
|
2018-04-15 02:51:02 +00:00
|
|
|
original: item
|
|
|
|
}))
|
|
|
|
};
|
|
|
|
}).catch(error => {
|
2018-04-17 22:18:04 +00:00
|
|
|
console.error(error);
|
2018-04-15 02:51:02 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = imgurAlbum;
|