mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
feat: card
This commit is contained in:
parent
cd0793655d
commit
ce3c509cd9
43 changed files with 508 additions and 7 deletions
53
lib/download.js
Normal file
53
lib/download.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { ZZZ_SQUARE_AVATAR, ZZZ_SQUARE_BANGBOO } from './mysapi/api.js';
|
||||
import { resourcesPath } from './path.js';
|
||||
|
||||
const ZZZ_SQUARE_AVATAR_PATH = path.join(resourcesPath, 'square_avatar');
|
||||
const ZZZ_SQUARE_BANGBOO_PATH = path.join(
|
||||
resourcesPath,
|
||||
'bangboo_square_avatar'
|
||||
);
|
||||
const ZZZ_GUIDES_PATH = path.join(resourcesPath, 'guides');
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string | number} charID
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
export const getSquareAvatar = async charID => {
|
||||
const filename = `role_square_avatar_${charID}.png`;
|
||||
const avatarPath = path.join(ZZZ_SQUARE_AVATAR_PATH, filename);
|
||||
if (fs.existsSync(avatarPath)) return avatarPath;
|
||||
const url = `${ZZZ_SQUARE_AVATAR}/${filename}`;
|
||||
const savePath = avatarPath;
|
||||
const download = await fetch(url);
|
||||
const arrayBuffer = await download.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
if (!fs.existsSync(ZZZ_SQUARE_AVATAR_PATH)) {
|
||||
fs.mkdirSync(ZZZ_SQUARE_AVATAR_PATH, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(savePath, buffer);
|
||||
return avatarPath;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string | number} bangbooId
|
||||
* @returns Promise<string>
|
||||
*/
|
||||
export const getSquareBangboo = async bangbooId => {
|
||||
const filename = `bangboo_rectangle_avatar_${bangbooId}.png`;
|
||||
const bangbooPath = path.join(ZZZ_SQUARE_BANGBOO_PATH, filename);
|
||||
if (fs.existsSync(bangbooPath)) return bangbooPath;
|
||||
const url = `${ZZZ_SQUARE_BANGBOO}/${filename}`;
|
||||
const savePath = bangbooPath;
|
||||
const download = await fetch(url);
|
||||
const arrayBuffer = await download.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
if (!fs.existsSync(ZZZ_SQUARE_BANGBOO_PATH)) {
|
||||
fs.mkdirSync(ZZZ_SQUARE_BANGBOO_PATH, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(savePath, buffer);
|
||||
return bangbooPath;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue