代码拉取完成,页面将自动刷新
/**
* 下载文件
*/
const axios = require('axios');
const url = require('url');
const fs = require('fs-extra');
const path = require('path');
async function startDownFile(url, out_path, opts = {}) {
let file_stream = await axios.get(url, {
responseType: 'stream',
headers: {}
});
await new Promise((resolve, reject) => {
fs.ensureFileSync(out_path);
let writer = fs.createWriteStream(out_path);
// let img_size = Number(file_stream.headers['content-length']);
// let progress_bar = false;
writer.on('finish', resolve);
writer.on('error', reject);
// 推流
file_stream.data.pipe(writer);
});
console.log(`Download Success.`);
}
let fileList = [
'http://www.oct-huanleli-cd.cn/js/baseCheck.js?ts=4',
'http://www.oct-huanleli-cd.cn/js/Data.js'
];
// run
(async () => {
for (let i = 0, tmp; i < fileList.length; i++) {
tmp = fileList[i];
let url_pathname = url.parse(tmp)?.pathname;
await startDownFile(tmp, path.join(__dirname, 'auto-script/tmp', path.basename(url_pathname)));
}
})();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。