refactor: improve document segment naming logic by matching barcodes via page sets and including template name fallback
Build and Push Multi-Platform Images / build-and-push (push) Successful in 18s

This commit is contained in:
2026-05-05 15:58:26 +02:00
parent 61d97464c3
commit 23bfa8d83d
@@ -16,7 +16,7 @@ import {
ZoomInOutlined,
ZoomOutOutlined,
} from '@ant-design/icons';
import { inboxApi, type InboxFile, type PostprocessActionResult } from '../api/inbox';
import { inboxApi, type InboxBarcode, type InboxFile, type PostprocessActionResult } from '../api/inbox';
import { paperlessApi } from '../api/paperless';
const ZOOM_MIN = 0.5;
@@ -35,7 +35,7 @@ function buildDocuments(
pageCount: number,
splitPages: number[],
deletedPages: number[],
barcodes: import('../api/inbox').InboxBarcode[],
barcodes: InboxBarcode[],
): DocumentSegment[] {
if (pageCount === 0) return [];
const deleted = new Set(deletedPages);
@@ -55,15 +55,14 @@ function buildDocuments(
docs.push({ index: docs.length, pages: current, belegname: null });
}
// Belegname (DateinameTemplate) pro Segment bestimmen
// Belegname pro Segment: DateinameTemplate des zugehörigen Barcodes,
// Fallback auf templateName falls DateinameTemplate nicht konfiguriert.
const sortedBarcodes = [...barcodes].sort((a, b) => a.page - b.page);
return docs.map((seg) => {
let barcode: import('../api/inbox').InboxBarcode | undefined;
if (seg.index === 0) {
barcode = barcodes[0];
} else {
barcode = barcodes.find((b) => b.splitBefore && b.page === seg.pages[0]);
}
return { ...seg, belegname: barcode?.dateinameTemplate ?? null };
const pageSet = new Set(seg.pages);
const barcode = sortedBarcodes.find((b) => pageSet.has(b.page));
const belegname = barcode?.dateinameTemplate || barcode?.templateName || null;
return { ...seg, belegname };
});
}