feat: implement QuestionBank CRUD with pagination and template query
- Add pagination support to findAll (page, limit query params) - Add findByTemplateId method to service - Add GET /by-template/:templateId endpoint to controller - Service already includes CRUD for QuestionBank and QuestionBankItem
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
import { apiClient } from './apiClient';
|
||||
import { IndexingConfig } from '../types';
|
||||
|
||||
// web/services/uploadService.ts
|
||||
export const uploadService = {
|
||||
async uploadFile(file: File, authToken: string): Promise<any> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
|
||||
const response = await apiClient.request('/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.message || 'fileUploadFailed');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
},
|
||||
|
||||
async uploadFileWithConfig(file: File, config: IndexingConfig, authToken: string): Promise<any> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
formData.append('chunkSize', config.chunkSize.toString());
|
||||
formData.append('chunkOverlap', config.chunkOverlap.toString());
|
||||
formData.append('embeddingModelId', config.embeddingModelId);
|
||||
|
||||
|
||||
if (config.mode) {
|
||||
formData.append('mode', config.mode);
|
||||
}
|
||||
|
||||
// 分類を追加(指定されている場合)
|
||||
if (config.groupIds && config.groupIds.length > 0) {
|
||||
formData.append('groupIds', JSON.stringify(config.groupIds));
|
||||
}
|
||||
|
||||
const response = await apiClient.request('/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.message || 'fileUploadFailed');
|
||||
}
|
||||
|
||||
return response.json();
|
||||
},
|
||||
|
||||
async uploadText(content: string, title: string, config: IndexingConfig, authToken: string): Promise<any> {
|
||||
const { data } = await apiClient.post('/upload/text', {
|
||||
content,
|
||||
title,
|
||||
chunkSize: config.chunkSize.toString(),
|
||||
chunkOverlap: config.chunkOverlap.toString(),
|
||||
embeddingModelId: config.embeddingModelId,
|
||||
mode: config.mode
|
||||
});
|
||||
return data;
|
||||
},
|
||||
|
||||
|
||||
async recommendMode(file: File): Promise<any> {
|
||||
|
||||
if (!file || !file.name) {
|
||||
return {
|
||||
recommendedMode: 'fast',
|
||||
reason: 'invalidFile',
|
||||
warnings: ['incompleteFileInfo'],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const ext = file.name.toLowerCase().split('.').pop();
|
||||
const sizeMB = file.size / (1024 * 1024);
|
||||
|
||||
const preciseFormats = ['pdf', 'doc', 'docx', 'ppt', 'pptx'];
|
||||
const supportedFormats = [...preciseFormats, 'xls', 'xlsx', 'txt', 'md', 'html', 'json', 'csv'];
|
||||
|
||||
if (!supportedFormats.includes(ext || '')) {
|
||||
return {
|
||||
recommendedMode: 'fast',
|
||||
reason: `unsupportedFileFormat`,
|
||||
reasonArgs: [ext],
|
||||
warnings: ['willUseFastMode'],
|
||||
};
|
||||
}
|
||||
|
||||
if (!preciseFormats.includes(ext || '')) {
|
||||
return {
|
||||
recommendedMode: 'fast',
|
||||
reason: `formatNoPrecise`,
|
||||
reasonArgs: [ext],
|
||||
warnings: ['willUseFastMode'],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if (sizeMB < 5) {
|
||||
return {
|
||||
recommendedMode: 'fast',
|
||||
reason: 'smallFileFastOk',
|
||||
estimatedCost: 0,
|
||||
estimatedTime: sizeMB * 2,
|
||||
warnings: [],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if (sizeMB < 50) {
|
||||
return {
|
||||
recommendedMode: 'precise',
|
||||
reason: 'mixedContentPreciseRecommended',
|
||||
estimatedCost: Math.max(0.01, sizeMB * 0.01),
|
||||
estimatedTime: sizeMB * 8,
|
||||
warnings: ['willIncurApiCost'],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
recommendedMode: 'precise',
|
||||
reason: 'largeFilePreciseRecommended',
|
||||
estimatedCost: sizeMB * 0.015,
|
||||
estimatedTime: sizeMB * 12,
|
||||
warnings: ['longProcessingTime', 'highApiCost', 'considerFileSplitting'],
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user