Files
paperlessmanager/paperless-frontend/src/api/inbox.ts
T
bjoernpoettker 13b07dfa71
Build and Push Multi-Platform Images / build-and-push (push) Successful in 33s
feat: add functionality to manually split documents at specific pages via the UI and API
2026-05-05 17:51:53 +02:00

124 lines
3.3 KiB
TypeScript

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<string, number>;
barcodes: InboxBarcode[];
createdAt: string;
}
export interface Client {
Id: number;
Name: string;
PaperlessUserId: number;
}
export const inboxApi = {
list: () => api.get<InboxFile[]>('/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<Blob>(`/api/inbox/${encodeURIComponent(id)}/preview`, { responseType: 'blob' })
.then((r) => r.data),
thumbnailBlob: (id: string, page: number) =>
api
.get<Blob>(
`/api/inbox/${encodeURIComponent(id)}/pages/${page}/thumbnail`,
{ responseType: 'blob' },
)
.then((r) => r.data),
pagePreviewBlob: (id: string, page: number) =>
api
.get<Blob>(
`/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<Client[]>('/api/clients').then((r) => r.data),
};