mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 21:27:47 +00:00
typo: 代码注释
This commit is contained in:
parent
51b3908afd
commit
4c90ca5354
12 changed files with 457 additions and 139 deletions
|
|
@ -25,19 +25,24 @@ const ZZZ_SUIT_PATH = path.join(imageResourcesPath, 'suit');
|
|||
*/
|
||||
const downloadFile = async (url, savePath) => {
|
||||
const _download = async (url, savePath, retry = 0) => {
|
||||
// 重试次数超过 5 次则返回 null
|
||||
if (retry > 5) {
|
||||
return null;
|
||||
}
|
||||
// 下载文件
|
||||
try {
|
||||
const download = await fetch(url);
|
||||
const arrayBuffer = await download.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
// 保存文件
|
||||
if (!fs.existsSync(path.dirname(savePath))) {
|
||||
fs.mkdirSync(path.dirname(savePath), { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(savePath, buffer);
|
||||
// 返回保存路径
|
||||
return savePath;
|
||||
} catch (error) {
|
||||
// 下载失败,重试
|
||||
return await _download(url, savePath, retry + 1);
|
||||
}
|
||||
};
|
||||
|
|
@ -97,7 +102,7 @@ export const getWeaponImage = async id => {
|
|||
*/
|
||||
export const getRoleImage = async id => {
|
||||
const sprite = char.IDToCharSprite(id);
|
||||
if (sprite === null) return null;
|
||||
if (!sprite) return null;
|
||||
const filename = `IconRole${sprite}.png`;
|
||||
const rolePath = path.join(ZZZ_ROLE_PATH, filename);
|
||||
if (fs.existsSync(rolePath)) return rolePath;
|
||||
|
|
@ -114,7 +119,7 @@ export const getRoleImage = async id => {
|
|||
*/
|
||||
export const getRoleCircleImage = async id => {
|
||||
const sprite = char.IDToCharSprite(id);
|
||||
if (sprite === null) return null;
|
||||
if (!sprite) return null;
|
||||
const filename = `IconRoleCircle${sprite}.png`;
|
||||
const roleCirclePath = path.join(ZZZ_ROLE_CIRCLE_PATH, filename);
|
||||
if (fs.existsSync(roleCirclePath)) return roleCirclePath;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue