0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/server/api/canary/oembed.js
Hannah Wolfe 829e8ed010 Expanded requires of lib/common i18n and events
- Having these as destructured from the same package is hindering refactoring now
- Events should really only ever be used server-side
- i18n should be a shared module for now so it can be used everywhere until we figure out something better
- Having them seperate also allows us to lint them properly
2021-05-03 17:14:52 +01:00

38 lines
1.1 KiB
JavaScript

const config = require('../../../shared/config');
const externalRequest = require('../../lib/request-external');
const i18n = require('../../lib/common/i18n');
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));
}
}
};