mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
从syzoj系统导入题目
This commit is contained in:
1 parent
97b0d782b9
commit
ce3d11b999
12 files changed
+179
-34
No files matched your search
@@ -0,0 +1,23 @@
|
||||
const axios = require('axios');
|
||||
|
||||
async function get(url, options) {
|
||||
let res;
|
||||
try {
|
||||
res = await axios.get(url, options);
|
||||
} catch (e) {
|
||||
res = e;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
async function post(url, data, options) {
|
||||
let res;
|
||||
try {
|
||||
res = await axios.post(url, data, options);
|
||||
} catch (e) {
|
||||
res = e;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
module.exports = { get, post };
|
||||
@@ -0,0 +1,22 @@
|
||||
const axios = require('axios');
|
||||
const fs = require('fs');
|
||||
|
||||
async function download(url, path, retry = 3) {
|
||||
let r;
|
||||
try {
|
||||
const res = await axios.get(url, { responseType: 'stream' });
|
||||
if (path) {
|
||||
const w = await fs.createWriteStream(path);
|
||||
res.data.pipe(w);
|
||||
await new Promise((resolve, reject) => {
|
||||
w.on('finish', resolve);
|
||||
w.on('error', reject);
|
||||
});
|
||||
} else r = res.data;
|
||||
} catch (e) {
|
||||
if (retry) r = await download(url, path, retry - 1);
|
||||
else throw e;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
module.exports = download;
|
||||
Reference in new issue
Block a user