You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.9 KiB
54 lines
1.9 KiB
import { fetch } from "bun"
|
|
import fs from "node:fs"
|
|
import path from "node:path"
|
|
|
|
const output = path.resolve(__dirname, "../dist/zzzmh")
|
|
|
|
let totalPage = 1
|
|
async function downImageByPage(current: number) {
|
|
const res = await (await fetch("https://api.zzzmh.cn/v2/bz/v3/getData", {
|
|
method: "POST",
|
|
headers: {
|
|
'Content-Type': 'application/json;charset=utf-8',
|
|
referer: "https://bz.zzzmh.cn/"
|
|
},
|
|
body: `{ "size": 24, "current": ${current}, "sort": 0, "category": 0, "resolution": 0, "color": 0, "categoryId": 0, "ratio": 0 }`
|
|
})).json()
|
|
totalPage = res.data.totalPage
|
|
for (let i = 0; i < res.data.list.length; i++) {
|
|
const item = res.data.list[i];
|
|
console.log(`正在下载第${i + 1}张图片`);
|
|
await (() => {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
resolve(1)
|
|
}, Math.random() * 2000 + 500);
|
|
})
|
|
})();
|
|
const stream = await (await fetch("https://api.zzzmh.cn/v2/bz/v3/getUrl/" + item.i + (item.t == 2 ? "21" : "11"))).arrayBuffer()
|
|
const p = path.resolve(output, "page-" + current + "/" + item.i + ".png")
|
|
if (!await checkExist(path.resolve(output, "page-" + current))) {
|
|
fs.mkdirSync(path.resolve(output, "page-" + current), { recursive: true })
|
|
}
|
|
const isExist = await checkExist(p)
|
|
if (!isExist) {
|
|
fs.writeFileSync(p, Buffer.from(stream!), { flag: "w" })
|
|
} else {
|
|
console.log("文件已存在,跳过下载", item.i + ".png");
|
|
}
|
|
}
|
|
}
|
|
|
|
function checkExist(path: string) {
|
|
return new Promise((resolve, reject) => {
|
|
fs.access(path, fs.constants.F_OK, (err) => {
|
|
if (err) {
|
|
resolve(false)
|
|
} else {
|
|
resolve(true)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
downImageByPage(2)
|