2021-01-21 11:57:52 +03:00
|
|
|
const config = require('../../../shared/config');
|
|
|
|
const externalRequest = require('../../lib/request-external');
|
2021-05-03 19:29:44 +03:00
|
|
|
const i18n = require('../../../shared/i18n');
|
2021-01-21 11:57:52 +03:00
|
|
|
const OEmbed = require('../../services/oembed');
|
|
|
|
const oembed = new OEmbed({config, externalRequest, i18n});
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
docName: 'oembed',
|
|
|
|
|
|
|
|
read: {
|
|
|
|
permissions: false,
|
|
|
|
data: [
|
|
|
|
'url',
|
|
|
|
'type'
|
|
|
|
],
|
|
|
|
options: [],
|
|
|
|
query({data}) {
|
|
|
|
let {url, type} = data;
|
|
|
|
|
|
|
|
if (type === 'bookmark') {
|
|
|
|
return oembed.fetchBookmarkData(url)
|
|
|
|
.catch(oembed.errorHandler(url));
|
|
|
|
}
|
|
|
|
|
|
|
|
return oembed.fetchOembedData(url).then((response) => {
|
|
|
|
if (!response && !type) {
|
|
|
|
return oembed.fetchBookmarkData(url);
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}).then((response) => {
|
|
|
|
if (!response) {
|
|
|
|
return oembed.unknownProvider(url);
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}).catch(oembed.errorHandler(url));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|