File size: 1,351 Bytes
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
import axios from 'axios'
import type { ProcessResponse, ReviewAction, ReviewState, SessionData } from './types'

const http = axios.create({ baseURL: '/' })

export const api = {
  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)}`
  },
}