feat: add functionality to manually split documents at specific pages via the UI and API
Build and Push Multi-Platform Images / build-and-push (push) Successful in 33s
Build and Push Multi-Platform Images / build-and-push (push) Successful in 33s
This commit is contained in:
@@ -59,6 +59,16 @@ export class InboxDocument {
|
||||
})
|
||||
Rotations!: Record<string, number>;
|
||||
|
||||
@Column({
|
||||
type: 'json',
|
||||
nullable: true,
|
||||
transformer: {
|
||||
to: (v: number[] | null | undefined) => (v && v.length ? v : null),
|
||||
from: (v: number[] | null) => v ?? [],
|
||||
},
|
||||
})
|
||||
ManualSplitPages!: number[];
|
||||
|
||||
@CreateDateColumn()
|
||||
CreatedAt!: Date;
|
||||
|
||||
|
||||
@@ -88,6 +88,17 @@ export class InboxController {
|
||||
await this.inboxService.deletePage(id, page, preferredUsername);
|
||||
}
|
||||
|
||||
@Post(':id/pages/:page/split')
|
||||
@HttpCode(204)
|
||||
async toggleManualSplit(
|
||||
@Param('id') id: string,
|
||||
@Param('page', ParseIntPipe) page: number,
|
||||
@Request() req: any,
|
||||
): Promise<void> {
|
||||
const preferredUsername: string | null = req.user?.preferredUsername ?? null;
|
||||
await this.inboxService.toggleManualSplit(id, page, preferredUsername);
|
||||
}
|
||||
|
||||
@Post(':id/reset-edits')
|
||||
@HttpCode(204)
|
||||
async resetEdits(@Param('id') id: string, @Request() req: any): Promise<void> {
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface InboxFile {
|
||||
source: InboxSource;
|
||||
pageCount: number;
|
||||
deletedPages: number[];
|
||||
manualSplitPages: number[];
|
||||
rotations: Record<string, number>;
|
||||
barcodes: MatchedBarcode[];
|
||||
createdAt: string;
|
||||
@@ -60,6 +61,7 @@ export class InboxService {
|
||||
source: doc.Source,
|
||||
pageCount: doc.PageCount,
|
||||
deletedPages: [...(doc.DeletedPages ?? [])].sort((a, b) => a - b),
|
||||
manualSplitPages: [...(doc.ManualSplitPages ?? [])].sort((a, b) => a - b),
|
||||
rotations: { ...(doc.Rotations ?? {}) },
|
||||
barcodes: await this.barcodeScanner.getMatched(doc),
|
||||
createdAt: doc.CreatedAt.toISOString(),
|
||||
@@ -142,7 +144,7 @@ export class InboxService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt alle markierten Bearbeitungen (DeletedPages, Rotations) zurück.
|
||||
* Setzt alle markierten Bearbeitungen (DeletedPages, Rotations, ManualSplitPages) zurück.
|
||||
*/
|
||||
async resetEdits(id: string, preferredUsername: string | null): Promise<void> {
|
||||
const { doc } = await this.resolveDocument(id, preferredUsername);
|
||||
@@ -155,9 +157,31 @@ export class InboxService {
|
||||
doc.Rotations = {};
|
||||
changed = true;
|
||||
}
|
||||
if (doc.ManualSplitPages && doc.ManualSplitPages.length > 0) {
|
||||
doc.ManualSplitPages = [];
|
||||
changed = true;
|
||||
}
|
||||
if (changed) await this.documentRepo.save(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt oder entfernt einen manuellen Trennpunkt vor der angegebenen Seite.
|
||||
*/
|
||||
async toggleManualSplit(id: string, page: number, preferredUsername: string | null): Promise<void> {
|
||||
const { doc } = await this.resolveDocument(id, preferredUsername);
|
||||
if (!Number.isInteger(page) || page < 2 || page > doc.PageCount) {
|
||||
throw new BadRequestException('Ungültige Seitennummer für Trennung');
|
||||
}
|
||||
const splits = new Set<number>(doc.ManualSplitPages ?? []);
|
||||
if (splits.has(page)) {
|
||||
splits.delete(page);
|
||||
} else {
|
||||
splits.add(page);
|
||||
}
|
||||
doc.ManualSplitPages = Array.from(splits).sort((a, b) => a - b);
|
||||
await this.documentRepo.save(doc);
|
||||
}
|
||||
|
||||
async deleteDocument(id: string, preferredUsername: string | null): Promise<void> {
|
||||
const { doc } = await this.resolveDocument(id, preferredUsername);
|
||||
const dir = this.pageCache.documentDir(doc.Id);
|
||||
|
||||
Reference in New Issue
Block a user