mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-30 06:12:03 +03:00
273e220327
refs 829e8ed010
- i18n is used everywhere but only requires shared or external packages, therefore it's a good candidate for living in shared
- this reduces invalid requires across frontend and server, and lets us use it everywhere until we come up with a better option
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
const config = require('../../../shared/config');
|
|
const externalRequest = require('../../lib/request-external');
|
|
const i18n = require('../../../shared/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));
|
|
}
|
|
}
|
|
};
|