Improved missing gfycat handling. Added 'preview' marker to index.
This commit is contained in:
@@ -1,26 +1,27 @@
|
||||
'use strict';
|
||||
'use strict';
|
||||
|
||||
const util = require('util');
|
||||
const config = require('config');
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
function gfycat(post) {
|
||||
return fetch(`https://gfycat.com/cajax/get/${post.host.id}`).then(res => res.json()).then(res => {
|
||||
return {
|
||||
album: null,
|
||||
items: [{
|
||||
id: res.gfyItem.gfyName,
|
||||
url: res.gfyItem.webmUrl,
|
||||
title: res.gfyItem.title,
|
||||
description: res.gfyItem.description,
|
||||
type: 'video/webm',
|
||||
datetime: new Date(res.gfyItem.createDate * 1000),
|
||||
original: res.gfyItem
|
||||
}]
|
||||
};
|
||||
}).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
};
|
||||
async function gfycat(post) {
|
||||
const res = await fetch(`https://gfycat.com/cajax/get/${post.host.id}`);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.error) {
|
||||
throw new Error(data.error);
|
||||
}
|
||||
|
||||
return {
|
||||
album: null,
|
||||
items: [{
|
||||
id: data.gfyItem.gfyName,
|
||||
url: data.gfyItem.webmUrl,
|
||||
title: data.gfyItem.title,
|
||||
description: data.gfyItem.description,
|
||||
type: 'video/webm',
|
||||
datetime: new Date(data.gfyItem.createDate * 1000),
|
||||
original: data.gfyItem,
|
||||
}],
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = gfycat;
|
||||
|
||||
Reference in New Issue
Block a user