importService.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { API_BASE_URL } from '../utils/constants';
  2. export interface ImportTask {
  3. id: string;
  4. sourcePath: string;
  5. targetGroupId?: string;
  6. targetGroupName?: string;
  7. scheduledAt?: string;
  8. status: 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED';
  9. logs?: string;
  10. embeddingModelId?: string;
  11. chunkSize?: number;
  12. chunkOverlap?: number;
  13. mode?: string;
  14. createdAt: string;
  15. }
  16. export const importService = {
  17. create: async (token: string, data: {
  18. sourcePath: string;
  19. targetGroupId?: string;
  20. targetGroupName?: string;
  21. embeddingModelId: string;
  22. scheduledAt?: string;
  23. chunkSize?: number;
  24. chunkOverlap?: number;
  25. mode?: string;
  26. }): Promise<ImportTask> => {
  27. const response = await fetch(`${API_BASE_URL}/import-tasks`, {
  28. method: 'POST',
  29. headers: {
  30. 'Authorization': `Bearer ${token}`,
  31. 'Content-Type': 'application/json'
  32. },
  33. body: JSON.stringify(data)
  34. });
  35. if (!response.ok) throw new Error('Failed to create import task');
  36. return response.json();
  37. },
  38. getAll: async (token: string): Promise<ImportTask[]> => {
  39. const response = await fetch(`${API_BASE_URL}/import-tasks`, {
  40. headers: {
  41. 'Authorization': `Bearer ${token}`
  42. }
  43. });
  44. if (!response.ok) throw new Error('Failed to fetch import tasks');
  45. return response.json();
  46. },
  47. delete: async (token: string, id: string): Promise<void> => {
  48. const response = await fetch(`${API_BASE_URL}/import-tasks/${id}`, {
  49. method: 'DELETE',
  50. headers: {
  51. 'Authorization': `Bearer ${token}`
  52. }
  53. });
  54. if (!response.ok) throw new Error('Failed to delete import task');
  55. }
  56. };