Spaces:
Sleeping
Sleeping
File size: 1,729 Bytes
be54038 1007fa0 be54038 1007fa0 be54038 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import axios from 'axios'
import type { ProcessResponse, ReviewAction, ReviewState, SampleFile, SamplePack, SessionData } from './types'
const http = axios.create({ baseURL: '/' })
export const api = {
async getSamples(): Promise<SamplePack> {
const { data } = await http.get<SamplePack>('/api/samples')
return data
},
async downloadSampleFile(sample: SampleFile): Promise<File> {
const { data } = await http.get<Blob>(sample.url, { responseType: 'blob' })
return new File([data], sample.filename, { type: 'application/pdf' })
},
async processDocuments(files: File[]): Promise<ProcessResponse> {
const form = new FormData()
for (const f of files) form.append('files', f)
const { data } = await http.post<ProcessResponse>('/api/process', form, {
headers: { 'Content-Type': 'multipart/form-data' },
})
return data
},
async getSession(sessionId: string): Promise<SessionData> {
const { data } = await http.get<SessionData>(`/api/session/${sessionId}`)
return data
},
async getReviewState(sessionId: string): Promise<ReviewState> {
const { data } = await http.get<ReviewState>(`/api/session/${sessionId}/review-state`)
return data
},
async updateReview(
sessionId: string,
fieldPath: string,
action: ReviewAction,
overriddenValue?: string,
): Promise<void> {
await http.patch(`/api/session/${sessionId}/review`, {
field_path: fieldPath,
action,
overridden_value: overriddenValue ?? null,
})
},
/** URL to stream a PDF — used directly by the PDF viewer component */
pdfUrl(sessionId: string, filename: string): string {
return `/api/pdf/${sessionId}/${encodeURIComponent(filename)}`
},
}
|