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
@@ -175,4 +175,38 @@ export class InboxController {
const preferredUsername: string | null = req.user?.preferredUsername ?? null;
await this.inboxService.updateSource(id, body.source, preferredUsername);
}
@Post(':id/save-to-paperless')
@HttpCode(204)
async saveToPaperless(
@Param('id') id: string,
@Body() body: {
title: string;
date?: string;
documentTypeId?: number;
correspondentId?: number;
tagIds?: number[];
},
@Request() req: any,
): Promise<void> {
const preferredUsername: string | null = req.user?.preferredUsername ?? null;
await this.inboxService.saveToPaperless(id, preferredUsername, body);
}
@Post(':id/send-email')
@HttpCode(204)
async sendEmail(
@Param('id') id: string,
@Body() body: {
to: string;
subject: string;
body: string;
html?: string;
filename?: string;
},
@Request() req: any,
): Promise<void> {
const preferredUsername: string | null = req.user?.preferredUsername ?? null;
await this.inboxService.sendAsEmail(id, preferredUsername, body);
}
}
+5 -1
View File
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Module, forwardRef } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Client } from '../database/entities/client.entity';
import { UserClient } from '../database/entities/user-client.entity';
@@ -9,12 +9,16 @@ import { InboxService } from './inbox.service';
import { InboxMigrationService } from './inbox-migration.service';
import { BarcodeModule } from '../barcode/barcode.module';
import { InboxPostprocessorModule } from '../inbox-postprocessor/inbox-postprocessor.module';
import { PaperlessModule } from '../paperless/paperless.module';
import { PostprocessingModule } from '../postprocessing/postprocessing.module';
@Module({
imports: [
TypeOrmModule.forFeature([Client, UserClient, InboxDocument]),
BarcodeModule,
InboxPostprocessorModule,
forwardRef(() => PaperlessModule),
PostprocessingModule,
],
controllers: [InboxController, ClientsController],
providers: [InboxService, InboxMigrationService],
@@ -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);
}
}
}