UNPKG

node-mirai-fgo-gacha

Version:

node-mirai-sdk fgo gacha plugin

45 lines (39 loc) 1.29 kB
const fs = require('fs'); const path = require('path'); const Progress = require('progress'); const download = require('./download'); const parallel = require('./parallel'); /** * @typedef { object } iconsObject * @property { string[] } svtIcons * @property { string[] } cftIcons */ /** * @method downloadIcons * @description Read icons.json and download icons * @param { function } logger */ const downloadIcons = async (log = false, overwrite = false) => { /** @type { iconsObject } */ const icons = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), '.fgo-gacha/statics/icons.json'))); for (let key in icons) { const bar = new Progress(`[Init] Downloading ${key} :bar [:current/:total]`, { total: icons[key].length, width: 20, complete: '█', incomplete: '░' }); /** * @function downloadIcon * @param { string } icon icon path */ const downloadIcon = async icon => { const src = `https://fgo.wiki${encodeURI(icon)}`; const dist = path.resolve(process.cwd(), '.fgo-gacha/statics/icons', icon.replace('/images', '').replace(/\//g, '_')); await download(src, dist, overwrite); log && bar.tick(); } await parallel(icons[key], downloadIcon, 10) } }; module.exports = downloadIcons;