(
file: File | string,
options?: ImportOptions,
onProgress?: (p: ImportProgress) => void
)
| 56 | |
| 57 | export class FetchImportAdapter implements ImportAdapter { |
| 58 | async importFile( |
| 59 | file: File | string, |
| 60 | options?: ImportOptions, |
| 61 | onProgress?: (p: ImportProgress) => void |
| 62 | ): Promise<ImportResult> { |
| 63 | if (typeof file === 'string') { |
| 64 | return { success: false, error: 'File path import is not supported in Web mode' } |
| 65 | } |
| 66 | |
| 67 | const form = new FormData() |
| 68 | form.append('file', file) |
| 69 | if (options?.formatId) form.append('formatId', options.formatId) |
| 70 | if (options?.chatIndex !== undefined) form.append('chatIndex', String(options.chatIndex)) |
| 71 | |
| 72 | const res = await fetchWithAuth(`${getBaseUrl()}/import`, { method: 'POST', body: form }) |
| 73 | |
| 74 | if (!res.ok) { |
| 75 | const text = await res.text() |
| 76 | return { success: false, error: `HTTP ${res.status}: ${text}` } |
| 77 | } |
| 78 | |
| 79 | return consumeSseStream<ImportResult>(res, { success: false, error: 'Unknown error' }, onProgress) |
| 80 | } |
| 81 | |
| 82 | async detectFormat(file: File | string): Promise<FormatInfo | null> { |
| 83 | if (typeof file === 'string') return null |
nothing calls this directly
no test coverage detected