feat: add save to paperless and send email functionality to inbox detail page with tiptap editor integration
Build and Push Multi-Platform Images / build-and-push (push) Successful in 46s

This commit is contained in:
2026-05-06 08:48:42 +02:00
parent 771c758fc7
commit 4f1f030423
8 changed files with 985 additions and 10 deletions
@@ -14,6 +14,9 @@ import {
InboxDocument,
type InboxSource,
} from '../database/entities/inbox-document.entity';
import { PaperlessService } from '../paperless/paperless.service';
import { MailService } from '../postprocessing/mail.service';
import { applyEditsToTemp, cleanupTemp } from '../inbox-postprocessor/edit-applier';
export interface InboxFile {
id: string;
@@ -41,6 +44,8 @@ export class InboxService {
private readonly pageCache: PageCacheService,
@InjectRepository(InboxDocument)
private readonly documentRepo: Repository<InboxDocument>,
private readonly paperlessService: PaperlessService,
private readonly mailService: MailService,
) {}
async listFiles(preferredUsername: string | null): Promise<InboxFile[]> {
@@ -249,4 +254,60 @@ export class InboxService {
const { doc, pdfPath } = await this.resolveDocument(id, preferredUsername);
return this.barcodeScanner.scanRegion(doc, pdfPath, page, x, y, w, h);
}
async saveToPaperless(
id: string,
preferredUsername: string | null,
opts: {
title: string;
date?: string;
documentTypeId?: number;
correspondentId?: number;
tagIds?: number[];
},
): Promise<void> {
const { doc, pdfPath } = await this.resolveDocument(id, preferredUsername);
let tmpPath: string | null = null;
try {
tmpPath = await applyEditsToTemp(doc, pdfPath);
await this.paperlessService.uploadDocument(tmpPath, {
title: opts.title,
created: opts.date,
documentType: opts.documentTypeId,
correspondent: opts.correspondentId,
tags: opts.tagIds,
});
} finally {
await cleanupTemp(tmpPath);
}
}
async sendAsEmail(
id: string,
preferredUsername: string | null,
opts: {
to: string;
subject: string;
body: string;
html?: string;
filename?: string;
},
): Promise<void> {
const { doc, pdfPath } = await this.resolveDocument(id, preferredUsername);
let tmpPath: string | null = null;
try {
tmpPath = await applyEditsToTemp(doc, pdfPath);
const content = await fs.readFile(tmpPath);
const filename = opts.filename ? `${opts.filename}.pdf` : doc.OriginalName;
await this.mailService.sendMail({
to: opts.to,
subject: opts.subject,
body: opts.body,
html: opts.html,
attachments: [{ filename, content }],
});
} finally {
await cleanupTemp(tmpPath);
}
}
}