0
0
mirror of https://github.com/fawazahmed0/exchange-api.git synced 2025-06-29 18:21:14 +00:00

Update cache-jsdelivr-api.js

This commit is contained in:
Fawaz Ahmed 2024-03-01 15:20:48 +05:30 committed by GitHub
parent ad654cd173
commit eb39481c93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,27 +1,25 @@
// Fetch all latest & todays links to cache the data by jsdelivr
let url = "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/"
let url = "https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api"
let apiLinks = [url]
let extensions = [".min.json", ".json"]
async function begin() {
for (let dateValue of ['latest', new Date().toISOString().substring(0, 10)]) {
for (let dateValue of ['latest', new Date().toISOString().substring(0, 10).replaceAll('-','.').replace(/\.0+(\d+)/gi , ".$1")]) {
let data = await fetch(`${url}/${dateValue}/currencies.json`).then(res => res.json())
let data = await fetch(`${url}@${dateValue}/v1/currencies.json`).then(res => res.json())
let currencies = Object.keys(data)
await multipleFetch(getURLs(`${url}/${dateValue}/currencies`))
await multipleFetch(getURLs(`${url}@${dateValue}/v1/currencies`))
for (let curr of currencies) {
let promiseHolder = []
promiseHolder.push(multipleFetch(getURLs(`${url}/${dateValue}/currencies/${curr}`)))
promiseHolder.push(multipleFetch(getURLs(`${url}@${dateValue}/v1/currencies/${curr}`)))
for (let curr2 of currencies)
promiseHolder.push(multipleFetch(getURLs(`${url}/${dateValue}/currencies/${curr}/${curr2}`)))
await Promise.allSettled(promiseHolder)
}
@ -46,4 +44,4 @@ function getURLs(endpoint, links) {
return extensions.map(ext => links.map(e => e + endpoint + ext)).flat()
}
begin()
begin()