chore: apply ESLint auto-fix across entire backend
Build and Push Multi-Platform Images / build-and-push (push) Successful in 41s
Build and Push Multi-Platform Images / build-and-push (push) Successful in 41s
Reformats code style (line breaks, indentation, type annotations) without changing logic. Also includes minor feature additions bundled in the same lint run (stats service, user-settings groups, agrarmonitor polling improvements). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,10 @@ import {
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import * as fs from 'fs/promises';
|
||||
import { BarcodeScannerService, type MatchedBarcode } from '../barcode/barcode-scanner.service';
|
||||
import {
|
||||
BarcodeScannerService,
|
||||
type MatchedBarcode,
|
||||
} from '../barcode/barcode-scanner.service';
|
||||
import { PageCacheService } from '../barcode/page-cache.service';
|
||||
import {
|
||||
InboxDocument,
|
||||
@@ -48,7 +51,14 @@ export class InboxService {
|
||||
|
||||
async listFiles(preferredUsername: string | null): Promise<InboxFile[]> {
|
||||
const where = preferredUsername
|
||||
? [{ Source: 'all' as InboxSource, IsScanned: true }, { Source: 'user' as InboxSource, OwnerUsername: preferredUsername, IsScanned: true }]
|
||||
? [
|
||||
{ Source: 'all' as InboxSource, IsScanned: true },
|
||||
{
|
||||
Source: 'user' as InboxSource,
|
||||
OwnerUsername: preferredUsername,
|
||||
IsScanned: true,
|
||||
},
|
||||
]
|
||||
: [{ Source: 'all' as InboxSource, IsScanned: true }];
|
||||
|
||||
const docs = await this.documentRepo.find({
|
||||
@@ -64,7 +74,9 @@ 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),
|
||||
manualSplitPages: [...(doc.ManualSplitPages ?? [])].sort(
|
||||
(a, b) => a - b,
|
||||
),
|
||||
rotations: { ...(doc.Rotations ?? {}) },
|
||||
barcodes: await this.barcodeScanner.getMatched(doc),
|
||||
createdAt: doc.CreatedAt.toISOString(),
|
||||
@@ -73,7 +85,10 @@ export class InboxService {
|
||||
return files;
|
||||
}
|
||||
|
||||
async resolveDocument(id: string, preferredUsername: string | null): Promise<ResolvedDocument> {
|
||||
async resolveDocument(
|
||||
id: string,
|
||||
preferredUsername: string | null,
|
||||
): Promise<ResolvedDocument> {
|
||||
const doc = await this.documentRepo.findOne({ where: { Id: id } });
|
||||
if (!doc) throw new NotFoundException('Dokument nicht gefunden');
|
||||
if (doc.Source === 'user' && doc.OwnerUsername !== preferredUsername) {
|
||||
@@ -85,7 +100,9 @@ export class InboxService {
|
||||
const stat = await fs.stat(pdfPath);
|
||||
if (!stat.isFile()) throw new Error('not a file');
|
||||
} catch (err: any) {
|
||||
this.logger.warn(`Datei fehlt trotz DB-Eintrag (${doc.Id}): ${err.message}`);
|
||||
this.logger.warn(
|
||||
`Datei fehlt trotz DB-Eintrag (${doc.Id}): ${err.message}`,
|
||||
);
|
||||
throw new NotFoundException('Dokument nicht gefunden');
|
||||
}
|
||||
|
||||
@@ -135,7 +152,7 @@ export class InboxService {
|
||||
if (!Number.isInteger(page) || page < 1 || page > doc.PageCount) {
|
||||
throw new NotFoundException('Seite nicht gefunden');
|
||||
}
|
||||
const normalized = ((Math.round(rotation / 90) * 90) % 360 + 360) % 360;
|
||||
const normalized = (((Math.round(rotation / 90) * 90) % 360) + 360) % 360;
|
||||
const next: Record<string, number> = { ...(doc.Rotations ?? {}) };
|
||||
if (normalized === 0) {
|
||||
delete next[String(page)];
|
||||
@@ -149,7 +166,10 @@ export class InboxService {
|
||||
/**
|
||||
* Setzt alle markierten Bearbeitungen (DeletedPages, Rotations, ManualSplitPages) zurück.
|
||||
*/
|
||||
async resetEdits(id: string, preferredUsername: string | null): Promise<void> {
|
||||
async resetEdits(
|
||||
id: string,
|
||||
preferredUsername: string | null,
|
||||
): Promise<void> {
|
||||
const { doc } = await this.resolveDocument(id, preferredUsername);
|
||||
let changed = false;
|
||||
if (doc.DeletedPages && doc.DeletedPages.length > 0) {
|
||||
@@ -170,7 +190,11 @@ export class InboxService {
|
||||
/**
|
||||
* Setzt oder entfernt einen manuellen Trennpunkt vor der angegebenen Seite.
|
||||
*/
|
||||
async toggleManualSplit(id: string, page: number, preferredUsername: string | null): Promise<void> {
|
||||
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');
|
||||
@@ -185,14 +209,19 @@ export class InboxService {
|
||||
await this.documentRepo.save(doc);
|
||||
}
|
||||
|
||||
async deleteDocument(id: string, preferredUsername: string | null): Promise<void> {
|
||||
async deleteDocument(
|
||||
id: string,
|
||||
preferredUsername: string | null,
|
||||
): Promise<void> {
|
||||
const { doc } = await this.resolveDocument(id, preferredUsername);
|
||||
const dir = this.pageCache.documentDir(doc.Id);
|
||||
await this.documentRepo.delete(doc.Id);
|
||||
try {
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
} catch (err: any) {
|
||||
this.logger.warn(`Dokument-Ordner konnte nicht gelöscht werden (${dir}): ${err.message}`);
|
||||
this.logger.warn(
|
||||
`Dokument-Ordner konnte nicht gelöscht werden (${dir}): ${err.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +260,9 @@ export class InboxService {
|
||||
doc.OwnerUsername = null;
|
||||
} else {
|
||||
if (!preferredUsername) {
|
||||
throw new BadRequestException('Benutzername erforderlich für persönlichen Scan');
|
||||
throw new BadRequestException(
|
||||
'Benutzername erforderlich für persönlichen Scan',
|
||||
);
|
||||
}
|
||||
doc.Source = 'user';
|
||||
doc.OwnerUsername = preferredUsername;
|
||||
@@ -260,7 +291,9 @@ export class InboxService {
|
||||
): Promise<{ buffer: Buffer; filename: string }> {
|
||||
const { doc, pdfPath } = await this.resolveDocument(id, preferredUsername);
|
||||
const deleted = new Set(doc.DeletedPages ?? []);
|
||||
const safePages = pages.filter((p) => p >= 1 && p <= doc.PageCount && !deleted.has(p));
|
||||
const safePages = pages.filter(
|
||||
(p) => p >= 1 && p <= doc.PageCount && !deleted.has(p),
|
||||
);
|
||||
const buffer = await buildSegmentBuffer(doc, pdfPath, safePages);
|
||||
return { buffer, filename: doc.OriginalName };
|
||||
}
|
||||
@@ -274,7 +307,14 @@ export class InboxService {
|
||||
body: string;
|
||||
html?: string;
|
||||
segments: { pages: number[]; filename: string }[];
|
||||
smtpOverride?: { host: string; port: number; secure: boolean; user: string; pass: string; from: string };
|
||||
smtpOverride?: {
|
||||
host: string;
|
||||
port: number;
|
||||
secure: boolean;
|
||||
user: string;
|
||||
pass: string;
|
||||
from: string;
|
||||
};
|
||||
},
|
||||
): Promise<void> {
|
||||
const { doc, pdfPath } = await this.resolveDocument(id, preferredUsername);
|
||||
@@ -282,9 +322,13 @@ export class InboxService {
|
||||
|
||||
const attachments = await Promise.all(
|
||||
opts.segments.map(async (seg) => {
|
||||
const safePages = seg.pages.filter((p) => p >= 1 && p <= doc.PageCount && !deleted.has(p));
|
||||
const safePages = seg.pages.filter(
|
||||
(p) => p >= 1 && p <= doc.PageCount && !deleted.has(p),
|
||||
);
|
||||
const content = await buildSegmentBuffer(doc, pdfPath, safePages);
|
||||
const filename = seg.filename.endsWith('.pdf') ? seg.filename : `${seg.filename}.pdf`;
|
||||
const filename = seg.filename.endsWith('.pdf')
|
||||
? seg.filename
|
||||
: `${seg.filename}.pdf`;
|
||||
return { filename, content };
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user