-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from ndaidong/v2.0.0
v2.0.0
- Loading branch information
Showing
33 changed files
with
1,382 additions
and
1,249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// config | ||
|
||
const fetchOptions = { | ||
headers: { | ||
'user-agent': 'Mozilla/5.0 (X11; Linux i686; rv:94.0) Gecko/20100101 Firefox/94.0', | ||
accept: 'application/json; charset=utf-8' | ||
}, | ||
responseType: 'json', | ||
timeout: 30 * 1e3, | ||
redirect: 'follow' | ||
} | ||
|
||
module.exports = { | ||
fetchOptions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,28 @@ | ||
// main | ||
/** | ||
* oembed parser | ||
* @ndaidong | ||
**/ | ||
|
||
const { | ||
isValidURL, | ||
findProvider, | ||
fetchEmbed, | ||
providersFromList | ||
} = require('./utils') | ||
const isValidURL = require('./utils/isValidURL') | ||
const fetchEmbed = require('./utils/fetchEmbed') | ||
|
||
const defaultProviderList = require('./utils/providers.json') | ||
let providers = providersFromList(defaultProviderList) | ||
const provider = require('./utils/provider') | ||
|
||
const extract = async (url, params = {}) => { | ||
if (!isValidURL(url)) { | ||
throw new Error('Invalid input URL') | ||
} | ||
const p = findProvider(url, providers) | ||
const p = provider.find(url) | ||
if (!p) { | ||
throw new Error(`No provider found with given url "${url}"`) | ||
} | ||
const data = await fetchEmbed(url, p, params) | ||
return data | ||
} | ||
|
||
const hasProvider = (url) => { | ||
return findProvider(url, providers) !== null | ||
} | ||
|
||
const setProviderList = (list) => { | ||
providers = providersFromList(list) | ||
} | ||
|
||
module.exports = { | ||
extract, | ||
hasProvider, | ||
setProviderList | ||
hasProvider: provider.has, | ||
findProvider: provider.find, | ||
setProviderList: provider.set | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.