2021-01-14 17:01:43 +00:00
|
|
|
const config = require('../../../shared/config');
|
|
|
|
const externalRequest = require('../../lib/request-external');
|
2021-04-27 14:18:04 +01:00
|
|
|
const i18n = require('../../lib/common/i18n');
|
2021-01-14 17:01:43 +00:00
|
|
|
const OEmbed = require('../../services/oembed');
|
|
|
|
const oembed = new OEmbed({config, externalRequest, i18n});
|
2020-06-08 15:06:00 +01:00
|
|
|
|
2019-08-09 19:41:24 +05:30
|
|
|
module.exports = {
|
|
|
|
docName: 'oembed',
|
|
|
|
|
|
|
|
read: {
|
|
|
|
permissions: false,
|
|
|
|
data: [
|
2019-08-27 19:31:02 +05:30
|
|
|
'url',
|
|
|
|
'type'
|
2019-08-09 19:41:24 +05:30
|
|
|
],
|
|
|
|
options: [],
|
|
|
|
query({data}) {
|
2019-08-27 19:31:02 +05:30
|
|
|
let {url, type} = data;
|
2019-08-09 19:41:24 +05:30
|
|
|
|
2019-08-27 19:31:02 +05:30
|
|
|
if (type === 'bookmark') {
|
2021-01-14 17:01:43 +00:00
|
|
|
return oembed.fetchBookmarkData(url)
|
|
|
|
.catch(oembed.errorHandler(url));
|
2019-08-09 19:41:24 +05:30
|
|
|
}
|
|
|
|
|
2021-01-14 17:01:43 +00:00
|
|
|
return oembed.fetchOembedData(url).then((response) => {
|
2019-08-27 19:31:02 +05:30
|
|
|
if (!response && !type) {
|
2021-01-14 17:01:43 +00:00
|
|
|
return oembed.fetchBookmarkData(url);
|
2019-08-09 19:41:24 +05:30
|
|
|
}
|
2019-08-27 19:31:02 +05:30
|
|
|
return response;
|
|
|
|
}).then((response) => {
|
|
|
|
if (!response) {
|
2021-01-14 17:01:43 +00:00
|
|
|
return oembed.unknownProvider(url);
|
2019-08-09 19:41:24 +05:30
|
|
|
}
|
2019-08-27 19:31:02 +05:30
|
|
|
return response;
|
2021-01-14 17:01:43 +00:00
|
|
|
}).catch(oembed.errorHandler(url));
|
2019-08-09 19:41:24 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|