refactor(modules): 拆分多模块工程并收口common基础模块

This commit is contained in:
2026-06-01 03:26:18 +08:00
parent 6fe1209801
commit 07ad8bb36b
231 changed files with 1690 additions and 172 deletions

View File

@@ -0,0 +1,30 @@
import { describe, expect, it, vi } from 'vitest';
import { uploadAttachment } from '../attachments';
import { post } from '../request';
vi.mock('../request', () => ({
post: vi.fn(),
}));
describe('attachments api', () => {
it('uploads attachment with multipart form data', () => {
const file = new File(['hello'], 'note.txt', { type: 'text/plain' });
uploadAttachment({
file,
sourceType: 'RAG',
sourceId: '1001',
});
const [url, body] = vi.mocked(post).mock.calls[0];
expect(url).toBe('/attachments/upload');
expect(body).toBeInstanceOf(FormData);
const entries = Array.from((body as FormData).entries());
expect(entries).toEqual([
['file', file],
['sourceType', 'RAG'],
['sourceId', '1001'],
]);
});
});

View File

@@ -0,0 +1,31 @@
import { post } from './request';
export interface AttachmentUploadRequest {
file: File;
sourceType: string;
sourceId?: string;
}
export interface AttachmentResponse {
id: string;
sourceType: string;
sourceId?: string | null;
originalName: string;
fileName: string;
fileSuffix?: string | null;
contentType?: string | null;
fileSize: number;
storageType: string;
fileUrl?: string | null;
remark?: string | null;
}
export function uploadAttachment(data: AttachmentUploadRequest) {
const formData = new FormData();
formData.append('file', data.file);
formData.append('sourceType', data.sourceType);
if (data.sourceId) {
formData.append('sourceId', data.sourceId);
}
return post<AttachmentResponse, FormData>('/attachments/upload', formData);
}