mirror of
https://github.com/yoimiya-kokomi/miao-plugin.git
synced 2024-11-22 15:36:27 +00:00
b5c1daf472
角色面板支持旅行者,暂未支持伤害计算 `#雷主天赋`、`#草主命座`功能升级
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
import fs from 'fs'
|
|
import request from 'request'
|
|
import { Data } from '../../components/index.js'
|
|
|
|
const _path = process.cwd()
|
|
const _root = _path + '/plugins/miao-plugin/'
|
|
const _cRoot = _root + 'resources/meta/character/'
|
|
|
|
export default class ImgDown {
|
|
constructor (name) {
|
|
this.name = name
|
|
this.imgs = []
|
|
}
|
|
|
|
add (key, url) {
|
|
this.imgs.push({
|
|
url,
|
|
file: `${this.name}/${key}.webp`
|
|
})
|
|
}
|
|
|
|
add2 (name, type, url) {
|
|
this.imgs.push({
|
|
url,
|
|
file: `../material/${type}/${name}.webp`
|
|
})
|
|
}
|
|
|
|
async _down (ds) {
|
|
if (fs.existsSync(`${_cRoot}/${ds.file}`)) {
|
|
// console.log(`已存在,跳过 ${ds.file}`)
|
|
return true
|
|
}
|
|
try {
|
|
let stream = fs.createWriteStream(`${_cRoot}/${ds.file}`)
|
|
await request('https://genshin.honeyhunterworld.com/' + ds.url).pipe(stream)
|
|
return new Promise((resolve) => {
|
|
stream.on('finish', () => {
|
|
console.log(`图像下载成功: ${ds.file}`)
|
|
resolve()
|
|
})
|
|
})
|
|
} catch (e) {
|
|
console.log(`图像下载失败: ${ds.file}`)
|
|
console.log(e)
|
|
return false
|
|
}
|
|
}
|
|
|
|
async download () {
|
|
await Data.asyncPool(5, this.imgs, this._down)
|
|
}
|
|
} |