import api from './client'; import type { BarcodeActionType } from './barcode-templates'; export type InboxSource = 'all' | 'user'; export interface InboxBarcode { page: number; value: string; templateId: number | null; templateName: string | null; dateinameTemplate: string | null; splitBefore: boolean; actions: BarcodeActionType[]; } export interface InboxFile { id: string; name: string; source: InboxSource; pageCount: number; deletedPages: number[]; manualSplitPages: number[]; rotations: Record; barcodes: InboxBarcode[]; createdAt: string; } export interface Client { Id: number; Name: string; PaperlessUserId: number; } export const inboxApi = { list: () => api.get('/api/inbox').then((r) => r.data), rescan: () => api .post<{ scanned: number; failed: number }>('/api/inbox/rescan', {}, { timeout: 600000 }) .then((r) => r.data), previewBlob: (id: string) => api .get(`/api/inbox/${encodeURIComponent(id)}/preview`, { responseType: 'blob' }) .then((r) => r.data), thumbnailBlob: (id: string, page: number) => api .get( `/api/inbox/${encodeURIComponent(id)}/pages/${page}/thumbnail`, { responseType: 'blob' }, ) .then((r) => r.data), pagePreviewBlob: (id: string, page: number) => api .get( `/api/inbox/${encodeURIComponent(id)}/pages/${page}/preview`, { responseType: 'blob' }, ) .then((r) => r.data), remove: (id: string) => api.delete(`/api/inbox/${encodeURIComponent(id)}`).then((r) => r.data), toggleSplit: (id: string, page: number) => api.post(`/api/inbox/${encodeURIComponent(id)}/pages/${page}/split`).then(() => {}), removePage: (id: string, page: number) => api .delete(`/api/inbox/${encodeURIComponent(id)}/pages/${page}`) .then((r) => r.data), resetEdits: (id: string) => api .post(`/api/inbox/${encodeURIComponent(id)}/reset-edits`) .then((r) => r.data), setPageRotation: (id: string, page: number, rotation: number) => api .put( `/api/inbox/${encodeURIComponent(id)}/pages/${page}/rotation`, { rotation }, ) .then((r) => r.data), postprocess: ( id: string, opts?: { sectionOffset?: number; processOnlyOne?: boolean; replaceDuplicate?: boolean }, ) => api .post<{ results: PostprocessActionResult[]; totalSections: number }>( `/api/inbox/${encodeURIComponent(id)}/postprocess`, opts ?? {}, ) .then((r) => r.data), updateSource: (id: string, source: InboxSource) => api .post(`/api/inbox/${encodeURIComponent(id)}/source`, { source }) .then((r) => r.data), scanRegion: (id: string, page: number, region: { x: number; y: number; w: number; h: number }) => api .post<{ found: string[] }>( `/api/inbox/${encodeURIComponent(id)}/pages/${page}/scan-region`, region, ) .then((r) => r.data), }; export interface PostprocessActionResult { sectionIndex: number; actionId: number; actionType: string; ok: boolean; skipped?: boolean; message?: string; duplicateOfDocumentId?: number; } export const clientsApi = { getMyClients: () => api.get('/api/clients').then((r) => r.data), };