importService.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. };