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

@@ -0,0 +1,30 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { uploadImageToGroupAlbum } from '../../src/web/group-album';
import { RequestUtil } from '../../src/web/request-util';
describe('group album image upload', () => {
afterEach(() => {
vi.restoreAllMocks();
vi.unstubAllGlobals();
});
it('rejects an MP4 before starting a remote upload', async () => {
const request = vi.spyOn(RequestUtil, 'HttpGetJson')
.mockRejectedValue(new Error('unexpected remote upload'));
const fetch = vi.fn();
vi.stubGlobal('fetch', fetch);
await expect(uploadImageToGroupAlbum(
{ skey: 'SK', p_skey: 'PSK' },
'12345',
'album-id',
'album-name',
'base64://AAAAGGZ0eXBtcDQyAAAAAG1wNDJpc29t',
'10000',
)).rejects.toThrow('群相册上传仅支持 JPEG、PNG、GIF、WebP 或 BMP 图片');
expect(request).not.toHaveBeenCalled();
expect(fetch).not.toHaveBeenCalled();
});
});