refactor: replace direct Paperless upload with client-side document download functionality
Build and Push Multi-Platform Images / build-and-push (push) Successful in 36s

This commit is contained in:
2026-05-06 09:30:53 +02:00
parent 4f1f030423
commit e08a5697f0
5 changed files with 34 additions and 137 deletions
@@ -176,21 +176,18 @@ export class InboxController {
await this.inboxService.updateSource(id, body.source, preferredUsername);
}
@Post(':id/save-to-paperless')
@HttpCode(204)
async saveToPaperless(
@Get(':id/download')
async download(
@Param('id') id: string,
@Body() body: {
title: string;
date?: string;
documentTypeId?: number;
correspondentId?: number;
tagIds?: number[];
},
@Request() req: any,
): Promise<void> {
@Res({ passthrough: true }) res: Response,
): Promise<StreamableFile> {
const preferredUsername: string | null = req.user?.preferredUsername ?? null;
await this.inboxService.saveToPaperless(id, preferredUsername, body);
const { buffer, filename } = await this.inboxService.getEditedPdfBuffer(id, preferredUsername);
const { Readable } = await import('stream');
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', `attachment; filename="${encodeURIComponent(filename)}"`);
return new StreamableFile(Readable.from(buffer));
}
@Post(':id/send-email')
+1 -3
View File
@@ -1,4 +1,4 @@
import { Module, forwardRef } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Client } from '../database/entities/client.entity';
import { UserClient } from '../database/entities/user-client.entity';
@@ -9,7 +9,6 @@ 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({
@@ -17,7 +16,6 @@ import { PostprocessingModule } from '../postprocessing/postprocessing.module';
TypeOrmModule.forFeature([Client, UserClient, InboxDocument]),
BarcodeModule,
InboxPostprocessorModule,
forwardRef(() => PaperlessModule),
PostprocessingModule,
],
controllers: [InboxController, ClientsController],
+4 -18
View File
@@ -14,7 +14,6 @@ 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';
@@ -44,7 +43,6 @@ export class InboxService {
private readonly pageCache: PageCacheService,
@InjectRepository(InboxDocument)
private readonly documentRepo: Repository<InboxDocument>,
private readonly paperlessService: PaperlessService,
private readonly mailService: MailService,
) {}
@@ -255,28 +253,16 @@ export class InboxService {
return this.barcodeScanner.scanRegion(doc, pdfPath, page, x, y, w, h);
}
async saveToPaperless(
async getEditedPdfBuffer(
id: string,
preferredUsername: string | null,
opts: {
title: string;
date?: string;
documentTypeId?: number;
correspondentId?: number;
tagIds?: number[];
},
): Promise<void> {
): Promise<{ buffer: Buffer; filename: string }> {
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,
});
const buffer = await fs.readFile(tmpPath);
return { buffer, filename: doc.OriginalName };
} finally {
await cleanupTemp(tmpPath);
}