diff --git a/README.md b/README.md index 42cd04a..5be547b 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ const getOembed = async (url) => { return oembed } catch (err) { console.trace(err) - return null + return null } } @@ -72,7 +72,17 @@ const data = getOembed('your url') console.log(data) ``` -Optional argument `params` is an object with it we can set `maxwidth` and/or `maxheight` those are used to scale embed size to fit your container size. Please refer [oEmbed/Full Spec/Consumer Request](https://oembed.com/#section2) for more info. +Optional argument `params` can be useful when you want to specify some additional customizations. + +Here are several popular params: + +- `maxwidth`: max width of embed size +- `maxheight`: max height of embed size +- `theme`: e.g, `dark` or `light` +- `lang`: e.g, 'en', 'fr', 'cn', 'vi', etc + +Note that some params are supported by these providers but not by the others. +Please see the provider's oEmbed API docs carefully for exact information. #### .hasProvider(String URL) diff --git a/package.json b/package.json index b966fef..c9ab8f1 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "2.0.0", + "version": "2.0.1", "name": "oembed-parser", "description": "Get oEmbed data from given URL.", "homepage": "https://www.npmjs.com/package/oembed-parser", diff --git a/src/main.test.js b/src/main.test.js index d5b1400..320565d 100644 --- a/src/main.test.js +++ b/src/main.test.js @@ -217,8 +217,6 @@ describe('test if extract() with some popular providers', () => { maxheight = 0 } = params - // `extract()` takes 2 args: url & params but not provider - // const result = await extract(url, provider, { maxwidth, maxheight }) const result = await extract(url, { maxwidth, maxheight }) expect(result).toBeTruthy() expect(checkFn(result)).toBe(true) diff --git a/src/utils/fetchEmbed.js b/src/utils/fetchEmbed.js index 136afa5..dd547cd 100644 --- a/src/utils/fetchEmbed.js +++ b/src/utils/fetchEmbed.js @@ -11,7 +11,7 @@ const getFacebookGraphToken = () => { const appId = env.FACEBOOK_APP_ID || '845078789498971' const clientToken = env.FACEBOOK_CLIENT_TOKEN || '8ff3ab4ddd45b8f018b35c4fb7edac62' - return `access_token=${appId}|${clientToken}` + return `${appId}|${clientToken}` } const getRegularUrl = (query, basseUrl) => { @@ -19,32 +19,26 @@ const getRegularUrl = (query, basseUrl) => { } const fetchEmbed = async (url, provider, params = {}) => { - const queries = [ - 'format=json', - `url=${encodeURIComponent(url)}` - ] - - // remove these if they're set to zero - if (params.maxwidth <= 0) { - delete params.maxwidth + const query = { + url, + format: 'json', + ...params } - if (params.maxheight <= 0) { - delete params.maxheight + + if (query.maxwidth <= 0) { + delete query.maxwidth + } + if (query.maxheight <= 0) { + delete query.maxheight } if (isFacebookGraphDependent(provider.providerUrl)) { - queries.push(getFacebookGraphToken()) + query.access_token = getFacebookGraphToken() } - const queryParams = new URLSearchParams(params).toString() - - let query = queries.join('&') - - if (queryParams) { - query = query + '&' + queryParams - } + const queryParams = new URLSearchParams(query).toString() - const link = getRegularUrl(query, provider.fetchEndpoint) + const link = getRegularUrl(queryParams, provider.fetchEndpoint) const body = retrieve(link) return body } diff --git a/src/utils/providers.backup.json b/src/utils/providers.backup.json index 43423ad..a5b4e0d 100644 --- a/src/utils/providers.backup.json +++ b/src/utils/providers.backup.json @@ -49,18 +49,17 @@ ] }, { - "provider_name": "Alpha App Net", - "provider_url": "https://alpha.app.net/browse/posts/", + "provider_name": "afreecaTV", + "provider_url": "https://www.afreecatv.com", "endpoints": [ { "schemes": [ - "https://alpha.app.net/*/post/*", - "https://photos.app.net/*/*" + "https://v.afree.ca/ST/", + "https://vod.afreecatv.com/ST/", + "https://vod.afreecatv.com/PLAYER/STATION/" ], - "url": "https://alpha-api.app.net/oembed", - "formats": [ - "json" - ] + "url": "https://openapi.afreecatv.com/vod/embedinfo", + "discovery": true } ] }, @@ -263,19 +262,6 @@ } ] }, - { - "provider_name": "AxiomNinja", - "provider_url": "http://axiom.ninja", - "endpoints": [ - { - "schemes": [ - "http://axiom.ninja/*" - ], - "url": "http://axiom.ninja/oembed/", - "discovery": true - } - ] - }, { "provider_name": "Backtracks", "provider_url": "https://backtracks.fm", @@ -331,19 +317,6 @@ } ] }, - { - "provider_name": "Bopp", - "provider_url": "http://www.bopp.tk", - "endpoints": [ - { - "schemes": [ - "http://i.bopp.tk/*" - ], - "url": "http://api.bopp.tk/v1/oembed", - "discovery": true - } - ] - }, { "provider_name": "Box Office Buz", "provider_url": "http://boxofficebuz.com", @@ -407,19 +380,6 @@ } ] }, - { - "provider_name": "Carbon Health", - "provider_url": "https://carbonhealth.com", - "endpoints": [ - { - "schemes": [ - "https://carbonhealth.com/practice/*" - ], - "url": "http://carbonhealth.com/oembed", - "discovery": true - } - ] - }, { "provider_name": "Catapult", "provider_url": "https://www.catapult.app/", @@ -462,22 +422,6 @@ } ] }, - { - "provider_name": "Chainflix", - "provider_url": "https://chainflix.net", - "endpoints": [ - { - "schemes": [ - "https://chainflix.net/video/*", - "https://chainflix.net/video/embed/*", - "https://*.chainflix.net/video/*", - "https://*.chainflix.net/video/embed/*" - ], - "url": "https://www.chainflix.net/video/oembed", - "discovery": true - } - ] - }, { "provider_name": "ChartBlocks", "provider_url": "http://www.chartblocks.com/", @@ -716,23 +660,6 @@ } ] }, - { - "provider_name": "Cyrano Systems", - "provider_url": "http://www.cyranosystems.com/", - "endpoints": [ - { - "schemes": [ - "https://staging.cyranosystems.com/msg/*", - "https://app.cyranosystems.com/msg/*" - ], - "url": "https://staging.cyranosystems.com/oembed", - "formats": [ - "json" - ], - "discovery": true - } - ] - }, { "provider_name": "Dailymotion", "provider_url": "https://www.dailymotion.com", @@ -834,18 +761,6 @@ } ] }, - { - "provider_name": "Dipity", - "provider_url": "http://www.dipity.com", - "endpoints": [ - { - "schemes": [ - "http://www.dipity.com/*/*/" - ], - "url": "http://www.dipity.com/oembed/timeline/" - } - ] - }, { "provider_name": "DocDroid", "provider_url": "https://www.docdroid.net/", @@ -892,18 +807,6 @@ } ] }, - { - "provider_name": "edocr", - "provider_url": "http://www.edocr.com", - "endpoints": [ - { - "schemes": [ - "http://edocr.com/docs/*" - ], - "url": "http://edocr.com/api/oembed" - } - ] - }, { "provider_name": "eduMedia", "provider_url": "https://www.edumedia-sciences.com/", @@ -931,18 +834,6 @@ } ] }, - { - "provider_name": "Embed Articles", - "provider_url": "http://embedarticles.com/", - "endpoints": [ - { - "schemes": [ - "http://embedarticles.com/*" - ], - "url": "http://embedarticles.com/oembed/" - } - ] - }, { "provider_name": "Embedery", "provider_url": "https://embedery.com/", @@ -1158,6 +1049,8 @@ "http://*.flickr.com/photos/*", "http://flic.kr/p/*", "https://*.flickr.com/photos/*", + "https://*.*.flickr.com/*/*", + "http://*.*.flickr.com/*/*", "https://flic.kr/p/*" ], "url": "https://www.flickr.com/services/oembed/", @@ -1220,18 +1113,6 @@ } ] }, - { - "provider_name": "FunnyOrDie", - "provider_url": "http://www.funnyordie.com/", - "endpoints": [ - { - "schemes": [ - "http://www.funnyordie.com/videos/*" - ], - "url": "http://www.funnyordie.com/oembed.{format}" - } - ] - }, { "provider_name": "Geograph Britain and Ireland", "provider_url": "https://www.geograph.org.uk/", @@ -1460,21 +1341,6 @@ } ] }, - { - "provider_name": "Hosted by You", - "provider_url": "https://hostedbyyou.com", - "endpoints": [ - { - "schemes": [ - "https://hostedbyyou.com/event/*" - ], - "url": "https://hostedbyyou.com/api/oembed", - "formats": [ - "json" - ] - } - ] - }, { "provider_name": "HuffDuffer", "provider_url": "http://huffduffer.com", @@ -1700,16 +1566,6 @@ } ] }, - { - "provider_name": "ivlismusic", - "provider_url": "https://music.ivlis.kr/", - "endpoints": [ - { - "url": "https://music.ivlis.kr/oembed", - "discovery": true - } - ] - }, { "provider_name": "Jovian", "provider_url": "https://jovian.ai/", @@ -2054,15 +1910,6 @@ } ] }, - { - "provider_name": "Microlink", - "provider_url": "http://api.microlink.io", - "endpoints": [ - { - "url": "https://api.microlink.io" - } - ] - }, { "provider_name": "Microsoft Stream", "provider_url": "https://stream.microsoft.com", @@ -2123,35 +1970,6 @@ } ] }, - { - "provider_name": "Modelo", - "provider_url": "http://modelo.io/", - "endpoints": [ - { - "schemes": [ - "https://beta.modelo.io/embedded/*" - ], - "url": "https://portal.modelo.io/oembed", - "discovery": false - } - ] - }, - { - "provider_name": "MorphCast", - "provider_url": "https://www.morphcast.com", - "endpoints": [ - { - "schemes": [ - "https://m-roll.morphcast.com/mroll/*" - ], - "url": "https://m-roll.morphcast.com/service/oembed", - "discovery": true, - "formats": [ - "json" - ] - } - ] - }, { "provider_name": "Music Box Maniacs", "provider_url": "https://musicboxmaniacs.com/", @@ -2343,6 +2161,20 @@ } ] }, + { + "provider_name": "Odysee", + "provider_url": "https://odysee.com", + "endpoints": [ + { + "schemes": [ + "https://odysee.com/*/*", + "https://odysee.com/*" + ], + "url": "https://odysee.com/$/oembed", + "discovery": true + } + ] + }, { "provider_name": "Official FM", "provider_url": "http://official.fm", @@ -2386,31 +2218,6 @@ } ] }, - { - "provider_name": "On Aol", - "provider_url": "http://on.aol.com/", - "endpoints": [ - { - "schemes": [ - "http://on.aol.com/video/*" - ], - "url": "http://on.aol.com/api" - } - ] - }, - { - "provider_name": "Opsomai", - "provider_url": "http://www.opsomai.com", - "endpoints": [ - { - "schemes": [ - "https://*.opsismedia.com/*" - ], - "url": "https://test-bysa.opsismedia.com/oembed.php", - "discovery": true - } - ] - }, { "provider_name": "Ora TV", "provider_url": "http://www.ora.tv/", @@ -2443,19 +2250,6 @@ } ] }, - { - "provider_name": "Oumy", - "provider_url": "https://www.oumy.com/", - "endpoints": [ - { - "schemes": [ - "https://www.oumy.com/v/*" - ], - "url": "https://www.oumy.com/oembed", - "discovery": true - } - ] - }, { "provider_name": "Outplayed.tv", "provider_url": "https://outplayed.tv/", @@ -2612,19 +2406,6 @@ } ] }, - { - "provider_name": "Polaris Share", - "provider_url": "https://www.polarishare.com/", - "endpoints": [ - { - "schemes": [ - "https://www.polarishare.com/*/*" - ], - "url": "https://api.polarishare.com/rest/api/oembed", - "discovery": true - } - ] - }, { "provider_name": "Poll Daddy", "provider_url": "http://polldaddy.com", @@ -2639,18 +2420,6 @@ } ] }, - { - "provider_name": "Port", - "provider_url": "http://www.sellwithport.com/", - "endpoints": [ - { - "schemes": [ - "https://app.sellwithport.com/#/buyer/*" - ], - "url": "https://api.sellwithport.com/v1.0/buyer/oembed" - } - ] - }, { "provider_name": "Portfolium", "provider_url": "https://portfolium.com", @@ -2663,19 +2432,6 @@ } ] }, - { - "provider_name": "posiXion", - "provider_url": "https://posixion.com/", - "endpoints": [ - { - "schemes": [ - "https://posixion.com/question/*", - "https://posixion.com/*/question/*" - ], - "url": "http://posixion.com/services/oembed/" - } - ] - }, { "provider_name": "Present", "provider_url": "https://present.do", @@ -2706,16 +2462,6 @@ } ] }, - { - "provider_name": "Qualifio", - "provider_url": "https://qualifio.com/", - "endpoints": [ - { - "url": "https://oembed.qualifio.com/", - "discovery": true - } - ] - }, { "provider_name": "Quiz.biz", "provider_url": "http://www.quiz.biz/", @@ -2836,32 +2582,6 @@ } ] }, - { - "provider_name": "RepubHub", - "provider_url": "http://repubhub.icopyright.net/", - "endpoints": [ - { - "schemes": [ - "http://repubhub.icopyright.net/freePost.act?*" - ], - "url": "http://repubhub.icopyright.net/oembed.act", - "discovery": true - } - ] - }, - { - "provider_name": "Resso", - "provider_url": "https://www.resso.app/", - "endpoints": [ - { - "schemes": [ - "https://h5.resso.com/*" - ], - "url": "https://h5.resso.com/oembed/", - "discovery": true - } - ] - }, { "provider_name": "ReverbNation", "provider_url": "https://www.reverbnation.com/", @@ -2876,16 +2596,6 @@ } ] }, - { - "provider_name": "RiffReporter", - "provider_url": "https://www.riffreporter.de/", - "endpoints": [ - { - "url": "https://www.riffreporter.de/service/oembed", - "discovery": true - } - ] - }, { "provider_name": "Roomshare", "provider_url": "http://roomshare.jp", @@ -3258,19 +2968,6 @@ } ] }, - { - "provider_name": "Spotful", - "provider_url": "https://bespotful.com", - "endpoints": [ - { - "schemes": [ - "http://play.bespotful.com/*" - ], - "url": "https://api.bespotful.com/oembed", - "discovery": true - } - ] - }, { "provider_name": "Spotify", "provider_url": "https://spotify.com/", @@ -3358,19 +3055,6 @@ } ] }, - { - "provider_name": "StreamOneCloud", - "provider_url": "https://www.streamone.nl", - "endpoints": [ - { - "schemes": [ - "https://content.streamonecloud.net/embed/*" - ], - "url": "https://content.streamonecloud.net/oembed", - "discovery": true - } - ] - }, { "provider_name": "Subscribi", "provider_url": "https://subscribi.io/", @@ -3551,22 +3235,6 @@ } ] }, - { - "provider_name": "TourHero", - "provider_url": "http://www.tourhero.com", - "endpoints": [ - { - "schemes": [ - "https://www.tourhero.com/*" - ], - "url": "https://oembed.tourhero.com/", - "discovery": true, - "formats": [ - "json" - ] - } - ] - }, { "provider_name": "Trinity Audio", "provider_url": "https://trinityaudio.ai", @@ -3625,6 +3293,7 @@ "endpoints": [ { "schemes": [ + "https://twitter.com/*", "https://twitter.com/*/status/*", "https://*.twitter.com/*/status/*" ], @@ -3669,21 +3338,6 @@ } ] }, - { - "provider_name": "Ubideo", - "provider_url": "https://player.ubideo.com/", - "endpoints": [ - { - "schemes": [ - "https://player.ubideo.com/*" - ], - "url": "https://player.ubideo.com/api/oembed.json", - "formats": [ - "json" - ] - } - ] - }, { "provider_name": "University of Cambridge Map", "provider_url": "https://map.cam.ac.uk", @@ -3709,20 +3363,6 @@ } ] }, - { - "provider_name": "UOL", - "provider_url": "https://mais.uol.com.br/", - "endpoints": [ - { - "schemes": [ - "https://*.uol.com.br/view/*", - "https://*.uol.com.br/video/*" - ], - "url": "https://mais.uol.com.br/apiuol/v3/oembed/view", - "discovery": true - } - ] - }, { "provider_name": "Upec.Pod", "provider_url": "https://pod.u-pec.fr/", @@ -3736,19 +3376,6 @@ } ] }, - { - "provider_name": "uppy", - "provider_url": "https://uppy.jp", - "endpoints": [ - { - "schemes": [ - "https://app.uppy.jp/_shares/video/*" - ], - "url": "https://api.uppy.jp/v1/oembed", - "discovery": true - } - ] - }, { "provider_name": "Ustream", "provider_url": "http://www.ustream.tv", @@ -3782,37 +3409,6 @@ } ] }, - { - "provider_name": "Utposts", - "provider_url": "https://www.utposts.com/", - "endpoints": [ - { - "schemes": [ - "https://www.utposts.com/products/*", - "http://www.utposts.com/products/*", - "https://utposts.com/products/*", - "http://utposts.com/products/*" - ], - "url": "https://www.utposts.com/api/oembed", - "formats": [ - "json" - ] - } - ] - }, - { - "provider_name": "Uttles", - "provider_url": "http://uttles.com", - "endpoints": [ - { - "schemes": [ - "http://uttles.com/uttle/*" - ], - "url": "http://uttles.com/api/reply/oembed", - "discovery": true - } - ] - }, { "provider_name": "VeeR VR", "provider_url": "http://veer.tv/", @@ -3857,41 +3453,15 @@ ] }, { - "provider_name": "VideoJug", - "provider_url": "http://www.videojug.com", - "endpoints": [ - { - "schemes": [ - "http://www.videojug.com/film/*", - "http://www.videojug.com/interview/*" - ], - "url": "http://www.videojug.com/oembed.{format}" - } - ] - }, - { - "provider_name": "Vidlit", - "provider_url": "https://vidl.it/", + "provider_name": "Videfit", + "provider_url": "https://videfit.com/", "endpoints": [ { "schemes": [ - "https://vidl.it/*" + "https://videfit.com/videos/*" ], - "url": "https://api.vidl.it/oembed", - "discovery": true - } - ] - }, - { - "provider_name": "Vidmizer", - "provider_url": "https://www.vidmizer.com/", - "endpoints": [ - { - "schemes": [ - "https://players-cdn-v2.vidmizer.com/*" - ], - "url": "https://app-v2.vidmizer.com/api/oembed", - "discovery": true + "url": "https://videfit.com/oembed", + "discovery": false } ] }, @@ -3946,19 +3516,6 @@ } ] }, - { - "provider_name": "Viziosphere", - "provider_url": "http://www.viziosphere.com", - "endpoints": [ - { - "schemes": [ - "http://viziosphere.com/3dphoto*" - ], - "url": "http://viziosphere.com/services/oembed/", - "discovery": true - } - ] - }, { "provider_name": "Vizydrop", "provider_url": "https://vizydrop.com", @@ -3999,20 +3556,6 @@ } ] }, - { - "provider_name": "Vlurb", - "provider_url": "https://www.vlurb.co/", - "endpoints": [ - { - "schemes": [ - "http://vlurb.co/video/*", - "https://vlurb.co/video/*" - ], - "url": "https://vlurb.co/oembed.json", - "discovery": true - } - ] - }, { "provider_name": "VoxSnap", "provider_url": "https://voxsnap.com/", @@ -4058,10 +3601,10 @@ }, { "provider_name": "wecandeo", - "provider_url": "http://www.wecandeo.com/", + "provider_url": "https://www.wecandeo.com/", "endpoints": [ { - "url": "http://play.wecandeo.com/oembed", + "url": "https://play.wecandeo.com/oembed", "discovery": true } ] @@ -4099,16 +3642,14 @@ }, { "provider_name": "wizer.me", - "provider_url": "http://www.wizer.me/", + "provider_url": "https://www.wizer.me/", "endpoints": [ { "schemes": [ - "http://*.wizer.me/learn/*", "https://*.wizer.me/learn/*", - "http://*.wizer.me/preview/*", "https://*.wizer.me/preview/*" ], - "url": "http://app.wizer.me/api/oembed.{format}", + "url": "https://app.wizer.me/api/oembed.{format}", "discovery": true } ] @@ -4142,74 +3683,26 @@ } ] }, - { - "provider_name": "Wootled", - "provider_url": "http://www.wootled.com/", - "endpoints": [ - { - "url": "http://www.wootled.com/oembed" - } - ] - }, { "provider_name": "WordPress.com", "provider_url": "http://wordpress.com/", - "endpoints": [ - { - "url": "http://public-api.wordpress.com/oembed/", - "discovery": true - } - ] - }, - { - "provider_name": "Xpression", - "provider_url": "https://web.xpression.jp", "endpoints": [ { "schemes": [ - "https://web.xpression.jp/video/*" - ], - "url": "https://web.xpression.jp/api/oembed", - "formats": [ - "json", - "xml" - ] - } - ] - }, - { - "provider_name": "Yes, I Know IT!", - "provider_url": "http://yesik.it", - "endpoints": [ - { - "schemes": [ - "http://yesik.it/*", - "http://www.yesik.it/*" - ], - "url": "http://yesik.it/s/oembed", - "formats": [ - "json" + "https://wordpress.com/*", + "http://wordpress.com/*", + "https://*.wordpress.com/*", + "http://*.wordpress.com/*", + "https://*.*.wordpress.com/*", + "http://*.*.wordpress.com/*", + "https://wp.me/*", + "http://wp.me/*" ], + "url": "http://public-api.wordpress.com/oembed/", "discovery": true } ] }, - { - "provider_name": "YFrog", - "provider_url": "http://yfrog.com/", - "endpoints": [ - { - "schemes": [ - "http://*.yfrog.com/*", - "http://yfrog.us/*" - ], - "url": "http://www.yfrog.com/api/oembed", - "formats": [ - "json" - ] - } - ] - }, { "provider_name": "YouTube", "provider_url": "https://www.youtube.com/", @@ -4219,7 +3712,8 @@ "https://*.youtube.com/watch*", "https://*.youtube.com/v/*", "https://youtu.be/*", - "https://*.youtube.com/playlist?list=*" + "https://*.youtube.com/playlist?list=*", + "https://youtube.com/playlist?list=*" ], "url": "https://www.youtube.com/oembed", "discovery": true diff --git a/src/utils/providers.json b/src/utils/providers.json index f4c6c1f..f3a4384 100644 --- a/src/utils/providers.json +++ b/src/utils/providers.json @@ -1049,9 +1049,9 @@ "http://*.flickr.com/photos/*", "http://flic.kr/p/*", "https://*.flickr.com/photos/*", + "https://flic.kr/p/*", "https://*.*.flickr.com/*/*", - "http://*.*.flickr.com/*/*", - "https://flic.kr/p/*" + "http://*.*.flickr.com/*/*" ], "url": "https://www.flickr.com/services/oembed/", "discovery": true @@ -3114,6 +3114,22 @@ } ] }, + { + "provider_name": "Synthesia", + "provider_url": "https://www.synthesia.io/", + "endpoints": [ + { + "schemes": [ + "https://share.synthesia.io/*" + ], + "url": "https://69jr5v75rc.execute-api.eu-west-1.amazonaws.com/prod/v2/oembed", + "formats": [ + "json" + ], + "discovery": true + } + ] + }, { "provider_name": "TED", "provider_url": "https://www.ted.com", @@ -3293,6 +3309,7 @@ "endpoints": [ { "schemes": [ + "https://twitter.com/*", "https://twitter.com/*/status/*", "https://*.twitter.com/*/status/*" ], @@ -3684,7 +3701,7 @@ }, { "provider_name": "WordPress.com", - "provider_url": "http://wordpress.com/", + "provider_url": "https://wordpress.com/", "endpoints": [ { "schemes": [ diff --git a/sync.js b/sync.js index 807a574..cde0326 100644 --- a/sync.js +++ b/sync.js @@ -5,11 +5,9 @@ const { writeFileSync } = require('fs') -const got = require('got') +const axios = require('axios') -const { - fetchOptions -} = require('./src/config') +const { getRequestOptions } = require('./src/config') const source = 'https://oembed.com/providers.json' const target = './src/utils/providers.json' @@ -18,24 +16,27 @@ const backup = './src/utils/providers.backup.json' const providerList = require(target) const merge = async () => { - // backup previous version - writeFileSync( - backup, - JSON.stringify(providerList, undefined, 2), - 'utf8' - ) - - const res = got(source, fetchOptions) - const data = await res.json() - - // merging - unlinkSync(target) - writeFileSync( - target, - JSON.stringify(data, undefined, 2), - 'utf8' - ) - console.log('Providers list has been updated') + try { + const res = await axios.get(source, getRequestOptions()) + + // backup previous version + writeFileSync( + backup, + JSON.stringify(providerList, undefined, 2), + 'utf8' + ) + + // merging + unlinkSync(target) + writeFileSync( + target, + JSON.stringify(res.data, undefined, 2), + 'utf8' + ) + console.log('Providers list has been updated') + } catch (err) { + console.trace(err) + } } merge()