feat:下载、删除图片资源

This commit is contained in:
bietiaop 2024-07-14 23:36:17 +08:00
parent 65652f87ef
commit b450b7f08b
8 changed files with 180 additions and 7 deletions

View file

@ -21,7 +21,7 @@ export function getStoken(e, mysid = '') {
try {
let cks = fs.readFileSync(file, 'utf-8');
cks = YAML.parse(cks);
for (let ck in cks) {
for (const ck in cks) {
if (cks[ck]['stuid'] === mysid) {
return cks[ck];
}
@ -47,7 +47,9 @@ export async function getAuthKey(e, _user, zzzUid, authAppid = 'csc') {
}
let ck = getStoken(e, uidData.ltuid);
if (!ck) {
throw new Error('获取cookie失败请确认绑定了 cookie');
throw new Error(
'获取cookie失败请确认绑定了cookie或者查询的UID是否与cookie对应请确认bot所使用的是绝区零UID'
);
}
if (uidData.ltuid !== ck.stuid) {
throw new Error(

View file

@ -83,3 +83,11 @@ export const atlasToID = name => {
const id = charNameToID(_name);
return id;
};
/**
* 获取所有角色ID
* @returns string[]
*/
export const getAllCharactersID = () => {
return Object.keys(PartnerId2SpriteId);
};

View file

@ -17,3 +17,11 @@ export function equipIdToSprite(equipId) {
}
return null;
}
/**
* 获取所有装备的id
* @returns {string[]}
*/
export function getAllEquipID() {
return Object.keys(equipData);
}

View file

@ -22,3 +22,11 @@ export const weaponFileNameToID = name => {
}
return null;
};
/**
* 获取所有武器的ID
* @returns string[]
*/
export const getAllWeaponID = () => {
return Object.keys(WeaponId2Sprite);
};

View file

@ -80,16 +80,13 @@ export const getSquareBangboo = async bangbooId => {
* @returns Promise<string>
*/
export const getWeaponImage = async id => {
logger.debug('getWeaponImage', id);
const name = weapon.IDToWeaponFileName(id);
logger.debug('getWeaponImage', name);
const filename = `${name}.png`;
const weaponPath = path.join(ZZZ_WEAPON_PATH, filename);
if (fs.existsSync(weaponPath)) return weaponPath;
const url = await getResourceRemotePath('weapon', filename);
const savePath = weaponPath;
const download = await downloadFile(url, savePath);
logger.debug('getWeaponImage', download);
return download;
};