cache-domains/diagnose/sites.js
2023-05-31 16:35:58 +03:00

34 lines
744 B
JavaScript

var cachedomains = {}
var urltext='';
const downloadJSON = (url, done)=> {
return fetch(url, {
method: 'GET',
})
.then(response => response.json())
.then(done)
}
const download = (url, done)=> {
return fetch(url, {
method: 'GET',
})
.then(response => response.text())
.then(done)
}
const downloadDomainFile = (data) => {
return download('/' + data.domain_files[0], (domains) => {
data.domains = domains.split('\n')
})
}
const downloadDomains = (done) => {
return downloadJSON('/cache_domains.json', (data)=> {
cachedomains = data.cache_domains;
const promises = []
for(const domain of cachedomains){
promises.push(downloadDomainFile(domain));
}
Promise
.all(promises) // (4)
.then(done);
})
}