mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-25 02:31:59 -05:00
Fixed function comlexity lint warning in oembeds
no issue - Logic with slightly more complex structure belongs to the service. Extracting it there also show's how little of an API the oembed service should actually expose
This commit is contained in:
parent
539145b0c6
commit
0703596ace
3 changed files with 33 additions and 32 deletions
|
@ -17,22 +17,7 @@ module.exports = {
|
|||
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));
|
||||
return oembed.fetchOembedDataFromUrl(url, type);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -17,22 +17,7 @@ module.exports = {
|
|||
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));
|
||||
return oembed.fetchOembedDataFromUrl(url, type);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -153,6 +153,12 @@ class OEmbed {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} _url
|
||||
* @param {string} cardType
|
||||
*
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
fetchOembedData(_url, cardType) {
|
||||
// parse the url then validate the protocol and host to make sure it's
|
||||
// http(s) and not an IP address or localhost to avoid potential access to
|
||||
|
@ -253,6 +259,31 @@ class OEmbed {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url - oembed URL
|
||||
* @param {string} type - card type
|
||||
*
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
async fetchOembedDataFromUrl(url, type) {
|
||||
if (type === 'bookmark') {
|
||||
return this.fetchBookmarkData(url)
|
||||
.catch(this.errorHandler(url));
|
||||
}
|
||||
|
||||
return this.fetchOembedData(url).then((response) => {
|
||||
if (!response && !type) {
|
||||
return this.fetchBookmarkData(url);
|
||||
}
|
||||
return response;
|
||||
}).then((response) => {
|
||||
if (!response) {
|
||||
return this.unknownProvider(url);
|
||||
}
|
||||
return response;
|
||||
}).catch(this.errorHandler(url));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OEmbed;
|
||||
|
|
Loading…
Add table
Reference in a new issue