Bump to ES6

This commit is contained in:
Peng-YM
2022-05-24 21:20:26 +08:00
parent 46e37df110
commit e228416718
23 changed files with 14866 additions and 3442 deletions

View File

@@ -1,30 +1,29 @@
const { HTTP } = require('./open-api');
import { HTTP } from './open-api';
const cache = new Map();
async function download(url, ua) {
ua = ua || 'Quantumult%20X/1.0.29 (iPhone14,5; iOS 15.4.1)';
const id = ua + url;
if (cache.has(id)) {
return cache.get(id);
}
export default async function download(url, ua) {
ua = ua || 'Quantumult%20X/1.0.29 (iPhone14,5; iOS 15.4.1)';
const id = ua + url;
if (cache.has(id)) {
return cache.get(id);
}
const $http = HTTP({
headers: {
'User-Agent': ua
}
});
const $http = HTTP({
headers: {
'User-Agent': ua,
},
});
const result = new Promise((resolve, reject) => {
$http.get(url).then((resp) => {
const body = resp.body;
if (body.replace(/\s/g, '').length === 0) reject(new Error('订阅内容为空!'));
else resolve(body);
});
});
const result = new Promise((resolve, reject) => {
$http.get(url).then((resp) => {
const body = resp.body;
if (body.replace(/\s/g, '').length === 0)
reject(new Error('订阅内容为空!'));
else resolve(body);
});
});
cache[id] = result;
return result;
cache.set(id, result);
return result;
}
module.exports = download;