2021-01-14 20:01:43 +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-14 20:01:43 +03:00
|
|
|
const OEmbed = require('../../services/oembed');
|
|
|
|
const oembed = new OEmbed({config, externalRequest, i18n});
|
2020-06-08 17:06:00 +03:00
|
|
|
|
2019-08-09 17:11:24 +03:00
|
|
|
module.exports = {
|
|
|
|
docName: 'oembed',
|
|
|
|
|
|
|
|
read: {
|
|
|
|
permissions: false,
|
|
|
|
data: [
|
2019-08-27 17:01:02 +03:00
|
|
|
'url',
|
|
|
|
'type'
|
2019-08-09 17:11:24 +03:00
|
|
|
],
|
|
|
|
options: [],
|
|
|
|
query({data}) {
|
2019-08-27 17:01:02 +03:00
|
|
|
let {url, type} = data;
|
2019-08-09 17:11:24 +03:00
|
|
|
|
2019-08-27 17:01:02 +03:00
|
|
|
if (type === 'bookmark') {
|
2021-01-14 20:01:43 +03:00
|
|
|
return oembed.fetchBookmarkData(url)
|
|
|
|
.catch(oembed.errorHandler(url));
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
|
|
|
|
2021-01-14 20:01:43 +03:00
|
|
|
return oembed.fetchOembedData(url).then((response) => {
|
2019-08-27 17:01:02 +03:00
|
|
|
if (!response && !type) {
|
2021-01-14 20:01:43 +03:00
|
|
|
return oembed.fetchBookmarkData(url);
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
2019-08-27 17:01:02 +03:00
|
|
|
return response;
|
|
|
|
}).then((response) => {
|
|
|
|
if (!response) {
|
2021-01-14 20:01:43 +03:00
|
|
|
return oembed.unknownProvider(url);
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
2019-08-27 17:01:02 +03:00
|
|
|
return response;
|
2021-01-14 20:01:43 +03:00
|
|
|
}).catch(oembed.errorHandler(url));
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|