2021-01-12 20:16:05 +03:00
|
|
|
const {fetchBookmarkData, fetchOembedData, errorHandler, unknownProvider} = require('../../services/oembed');
|
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') {
|
2020-03-02 17:24:26 +03:00
|
|
|
return fetchBookmarkData(url)
|
2020-06-08 17:06:00 +03:00
|
|
|
.catch(errorHandler(url));
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
|
|
|
|
2019-08-27 17:01:02 +03:00
|
|
|
return fetchOembedData(url).then((response) => {
|
|
|
|
if (!response && !type) {
|
|
|
|
return fetchBookmarkData(url);
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
2019-08-27 17:01:02 +03:00
|
|
|
return response;
|
|
|
|
}).then((response) => {
|
|
|
|
if (!response) {
|
|
|
|
return unknownProvider(url);
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
2019-08-27 17:01:02 +03:00
|
|
|
return response;
|
2020-06-08 17:06:00 +03:00
|
|
|
}).catch(errorHandler(url));
|
2019-08-09 17:11:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|