从syzoj系统导入题目

This commit is contained in:
masnn committed 2020-04-17 12:47:45 +08:00
1 parent 97b0d782b9
commit ce3d11b999
12 files changed
+179 -34

No files matched your search

+23
View File
@@ -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 };
+22
View File
@@ -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;