fix(group-album): validate image upload inputs

Reject unsupported media with a clear error before processing begins. Existing image upload behavior remains unchanged.

Refs #310
This commit is contained in:
DrSmoothl committed 2026-08-04 15:25:23 +08:00
1 parent 185ba8353b
commit 672802b424
2 files changed
+38 -1

No files matched your search

+8 -1
View File
@@ -221,8 +221,15 @@ export async function uploadImageToGroupAlbum(
filePath: string,
uin: string
): Promise<void> {
const { loadBinarySource } = await import('../highway/utils');
const { detectImageFormat, loadBinarySource } = await import('../highway/utils');
const loaded = await loadBinarySource(filePath, 'album image');
const format = detectImageFormat(loaded.bytes);
const isJpeg = loaded.bytes.length >= 2
&& loaded.bytes[0] === 0xFF
&& loaded.bytes[1] === 0xD8;
if (format.format === 1000 && !isJpeg) {
throw new Error('群相册上传仅支持 JPEG、PNG、GIF、WebP 或 BMP 图片');
}
let tempFile: string | null = null;
let actualPath = filePath;