Files
paperlessmanager/paperless-frontend/src/api/email-import.ts
T
bjoernpoettker 44d5206e07
Build and Push Multi-Platform Images / build-and-push (push) Successful in 33s
feat: implement checksum-based duplicate detection for split email attachments
2026-05-05 08:22:18 +02:00

74 lines
2.7 KiB
TypeScript

import api from './client';
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;
}
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 });
},
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;
},
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[]): Promise<{ success: boolean; results: any[] }> => {
const res = await api.post('/api/email-import/execute', { emailDate, attachments });
return res.data;
},
ensurePreviews: async (emailId: number): Promise<void> => {
await api.post(`/api/email-import/emails/${emailId}/ensure-previews`);
},
};