feat:优化图片保存逻辑

This commit is contained in:
Jerry 2025-10-05 00:44:20 +08:00
parent 9b0df2f281
commit b8f6f737e9

View File

@ -61,7 +61,11 @@ export class welcomeNewcomerSetting extends plugin {
const filePath = path.join(groupDir, '1'); const filePath = path.join(groupDir, '1');
try { try {
await fs.promises.mkdir(groupDir, { recursive: true }); if (!fs.existsSync(groupDir)) await fs.promises.mkdir(groupDir, { recursive: true });
const oldFiles = await fs.promises.readdir(groupDir);
for (const file of oldFiles) {
if (file.startsWith('1.')) await fs.promises.unlink(path.join(groupDir, file));
}
const res = await axios.get(imgUrl, { responseType: 'arraybuffer' }); const res = await axios.get(imgUrl, { responseType: 'arraybuffer' });
const contentType = res.headers['content-type'] || ''; const contentType = res.headers['content-type'] || '';
const ext = contentType.includes('gif') ? 'gif' : 'jpg'; const ext = contentType.includes('gif') ? 'gif' : 'jpg';