Files
paperlessmanager/paperless-frontend/src/api/email-import.ts
T

109 lines
4.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import api from './client';
import type { VergleichKennzahlen } from './paperless';
export interface CorrespondentMapping {
Id: number;
EmailAddress: string;
PaperlessCorrespondentId: number;
}
export interface AttachmentImportData {
attachmentId: number;
virtualId: string;
fileName: string;
pages?: { start: number; end: number };
type: 'MAIN' | 'ATTACHMENT' | 'IGNORE';
paperlessCorrespondentId?: number | null;
parentDocumentId?: number | null;
parentVirtualId?: string | null;
splitRanges?: { start: number; end: number }[];
barcode?: { x: number; y: number; nummer: string; datum: string; jahr: string };
belegnummer?: string;
isDuplicate?: boolean;
/** Stammdokument in Paperless, an das der Beleg als neue Version kommt */
versionZuDokumentId?: number | null;
}
export const emailImportApi = {
getMappings: async (): Promise<CorrespondentMapping[]> => {
const res = await api.get('/api/email-import/mappings');
return res.data;
},
addMapping: async (emailAddress: string, paperlessCorrespondentId: number): Promise<CorrespondentMapping> => {
const res = await api.post('/api/email-import/mappings', { emailAddress, paperlessCorrespondentId });
return res.data;
},
deleteMapping: async (id: number): Promise<void> => {
await api.delete(`/api/email-import/mappings/${id}`);
},
getCorrespondentByEmail: async (emailAddress: string): Promise<{ paperlessCorrespondentId: number | null }> => {
const res = await api.get('/api/email-import/correspondent', { params: { email: emailAddress } });
return res.data;
},
getBelegnummer: async (dateStr: string): Promise<{ nummer: string }> => {
const res = await api.get('/api/email-import/belegnummer', { params: { date: dateStr } });
return res.data;
},
releaseBelegnummer: async (dateStr: string, number: string): Promise<void> => {
await api.post('/api/email-import/belegnummer/release', { date: dateStr, number });
},
attachmentPdfBlob: async (attachmentId: number, pages?: { start: number; end: number }): Promise<Blob> => {
const res = await api.get(`/api/email-import/attachments/${attachmentId}/pdf`, {
params: pages ? { start: pages.start, end: pages.end } : undefined,
responseType: 'blob',
});
return res.data;
},
vergleich: async (
attachmentId: number,
paperlessDocumentId: number,
pages?: { start: number; end: number },
): Promise<VergleichKennzahlen> => {
const res = await api.post(`/api/email-import/attachments/${attachmentId}/vergleich`, { paperlessDocumentId, pages });
return res.data;
},
printPreview: async (attachmentId: number, barcodeData: any, pages?: { start: number; end: number }): Promise<Blob> => {
const res = await api.post(`/api/email-import/attachments/${attachmentId}/print-preview`, { ...barcodeData, _pages: pages }, {
responseType: 'blob',
});
return res.data;
},
// Prüft auf Duplikate – in Paperless und bei Importen, die dort noch verarbeitet werden.
checkDuplicate: async (attachmentId: number): Promise<boolean> => {
const res = await api.post<{ isDuplicate: boolean }>(`/api/email-import/attachments/${attachmentId}/check-duplicate`);
return res.data.isDuplicate;
},
checkSplitChecksum: async (attachmentId: number, pages: { start: number; end: number }): Promise<boolean> => {
const res = await api.post<{ isDuplicate: boolean }>(`/api/email-import/attachments/${attachmentId}/check-split-checksum`, { pages });
return res.data.isDuplicate;
},
executeImport: async (emailDate: string, attachments: AttachmentImportData[], jobId?: string): Promise<{ success: boolean; results: any[] }> => {
const res = await api.post('/api/email-import/execute', { emailDate, attachments, jobId }, { timeout: 300_000 });
return res.data;
},
getJobStatus: async (jobId: string): Promise<{ message: string; done: boolean } | null> => {
try {
const res = await api.get(`/api/email-import/jobs/${jobId}/status`);
return res.data;
} catch {
return null;
}
},
ensurePreviews: async (emailId: number): Promise<void> => {
await api.post(`/api/email-import/emails/${emailId}/ensure-previews`);
},
};