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:
@@ -1,4 +1,15 @@
|
||||
import { Controller, Get, Post, Param, Query, Res, Logger, NotFoundException, Patch, Body } from '@nestjs/common';
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Param,
|
||||
Query,
|
||||
Res,
|
||||
Logger,
|
||||
NotFoundException,
|
||||
Patch,
|
||||
Body,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import type { Response } from 'express';
|
||||
@@ -15,8 +26,10 @@ export class EmailController {
|
||||
|
||||
constructor(
|
||||
@InjectRepository(Email) private readonly emailRepo: Repository<Email>,
|
||||
@InjectRepository(Attachment) private readonly attachmentRepo: Repository<Attachment>,
|
||||
@InjectRepository(Content) private readonly contentRepo: Repository<Content>,
|
||||
@InjectRepository(Attachment)
|
||||
private readonly attachmentRepo: Repository<Attachment>,
|
||||
@InjectRepository(Content)
|
||||
private readonly contentRepo: Repository<Content>,
|
||||
private readonly paperlessService: PaperlessService,
|
||||
) {}
|
||||
|
||||
@@ -26,7 +39,8 @@ export class EmailController {
|
||||
@Query('status') status?: string,
|
||||
@Query('limit') limit?: string,
|
||||
) {
|
||||
const qb = this.emailRepo.createQueryBuilder('e')
|
||||
const qb = this.emailRepo
|
||||
.createQueryBuilder('e')
|
||||
.leftJoinAndSelect('e.Attachments', 'a')
|
||||
.orderBy('e.Date', 'DESC')
|
||||
.take(parseInt(limit ?? '50', 10));
|
||||
@@ -66,21 +80,28 @@ export class EmailController {
|
||||
const attachment = await this.attachmentRepo.findOne({ where: { Id: id } });
|
||||
if (!attachment) throw new NotFoundException('Anhang nicht gefunden');
|
||||
|
||||
const content = await this.contentRepo.findOne({ where: { AttachmentEntityId: id } });
|
||||
const content = await this.contentRepo.findOne({
|
||||
where: { AttachmentEntityId: id },
|
||||
});
|
||||
if (!content) throw new NotFoundException('Inhalt nicht gefunden');
|
||||
|
||||
res.setHeader('Content-Type', attachment.ContentType || 'application/octet-stream');
|
||||
res.setHeader('Content-Disposition', `inline; filename="${encodeURIComponent(attachment.FileName)}"`);
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
attachment.ContentType || 'application/octet-stream',
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
`inline; filename="${encodeURIComponent(attachment.FileName)}"`,
|
||||
);
|
||||
res.send(content.Content1);
|
||||
}
|
||||
|
||||
@Patch(':id/status')
|
||||
@RequirePermissions(Permission.MANAGE_ALL)
|
||||
async updateStatus(
|
||||
@Param('id') id: string,
|
||||
@Body('status') status: number,
|
||||
) {
|
||||
const email = await this.emailRepo.findOneOrFail({ where: { Id: parseInt(id, 10) } });
|
||||
async updateStatus(@Param('id') id: string, @Body('status') status: number) {
|
||||
const email = await this.emailRepo.findOneOrFail({
|
||||
where: { Id: parseInt(id, 10) },
|
||||
});
|
||||
email.Status = status;
|
||||
await this.emailRepo.save(email);
|
||||
this.logger.log(`E-Mail ${id} auf Status ${status} gesetzt.`);
|
||||
@@ -91,10 +112,14 @@ export class EmailController {
|
||||
@RequirePermissions(Permission.MANAGE_ALL)
|
||||
async checkAttachments(@Body() body: { includeProcessed?: boolean } = {}) {
|
||||
const { includeProcessed = false } = body;
|
||||
this.logger.log(`Starte manuelle Prüfung der E-Mail-Anhänge in Paperless... (includeProcessed=${includeProcessed})`);
|
||||
this.logger.log(
|
||||
`Starte manuelle Prüfung der E-Mail-Anhänge in Paperless... (includeProcessed=${includeProcessed})`,
|
||||
);
|
||||
|
||||
try {
|
||||
const whereCondition = includeProcessed ? [{ Status: 0 }, { Status: 1 }] : { Status: 0 };
|
||||
const whereCondition = includeProcessed
|
||||
? [{ Status: 0 }, { Status: 1 }]
|
||||
: { Status: 0 };
|
||||
const emails = await this.emailRepo.find({
|
||||
where: whereCondition,
|
||||
relations: ['Attachments'],
|
||||
@@ -116,25 +141,43 @@ export class EmailController {
|
||||
|
||||
for (const attachment of email.Attachments) {
|
||||
// Prüfe nur PDFs mit Checksumme
|
||||
if (attachment.ContentType === 'application/pdf' && attachment.Checksum) {
|
||||
this.logger.debug(`Prüfe Checksumme für E-Mail ${email.Id}, Anhang ${attachment.Id} (${attachment.FileName})`);
|
||||
if (
|
||||
attachment.ContentType === 'application/pdf' &&
|
||||
attachment.Checksum
|
||||
) {
|
||||
this.logger.debug(
|
||||
`Prüfe Checksumme für E-Mail ${email.Id}, Anhang ${attachment.Id} (${attachment.FileName})`,
|
||||
);
|
||||
try {
|
||||
const docId = await this.paperlessService.getDocumentIdByChecksum(attachment.Checksum);
|
||||
const docId = await this.paperlessService.getDocumentIdByChecksum(
|
||||
attachment.Checksum,
|
||||
);
|
||||
if (docId !== null) {
|
||||
this.logger.log(`Treffer! Anhang ${attachment.Id} (E-Mail ${email.Id}) → Paperless-Dokument ${docId}.`);
|
||||
this.logger.log(
|
||||
`Treffer! Anhang ${attachment.Id} (E-Mail ${email.Id}) → Paperless-Dokument ${docId}.`,
|
||||
);
|
||||
hasMatch = true;
|
||||
|
||||
// PaperlessDocumentId hinterlegen, falls noch nicht vorhanden
|
||||
const existingIds: Record<string, number> = attachment.PaperlessDocumentIds ?? {};
|
||||
const existingIds: Record<string, number> =
|
||||
attachment.PaperlessDocumentIds ?? {};
|
||||
if (!existingIds['full']) {
|
||||
attachment.PaperlessDocumentIds = { ...existingIds, full: docId };
|
||||
attachment.PaperlessDocumentIds = {
|
||||
...existingIds,
|
||||
full: docId,
|
||||
};
|
||||
await this.attachmentRepo.save(attachment);
|
||||
idsUpdated++;
|
||||
this.logger.log(`Anhang ${attachment.Id}: PaperlessDocumentIds aktualisiert (full=${docId}).`);
|
||||
this.logger.log(
|
||||
`Anhang ${attachment.Id}: PaperlessDocumentIds aktualisiert (full=${docId}).`,
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
this.logger.error(`Fehler bei Checksummen-Prüfung für Attachment ${attachment.Id}: ${err.message}`, err.stack);
|
||||
this.logger.error(
|
||||
`Fehler bei Checksummen-Prüfung für Attachment ${attachment.Id}: ${err.message}`,
|
||||
err.stack,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,18 +187,27 @@ export class EmailController {
|
||||
email.Status = 1;
|
||||
await this.emailRepo.save(email);
|
||||
updatedCount++;
|
||||
this.logger.log(`E-Mail ${email.Id} auf Status 1 (Verarbeitet) gesetzt.`);
|
||||
this.logger.log(
|
||||
`E-Mail ${email.Id} auf Status 1 (Verarbeitet) gesetzt.`,
|
||||
);
|
||||
}
|
||||
|
||||
if ((index + 1) % 10 === 0) {
|
||||
this.logger.log(`Zwischenstand: ${index + 1} von ${emails.length} E-Mails geprüft.`);
|
||||
this.logger.log(
|
||||
`Zwischenstand: ${index + 1} von ${emails.length} E-Mails geprüft.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.log(`Prüfung abgeschlossen. ${updatedCount} E-Mails aktualisiert, ${idsUpdated} Paperless-IDs ergänzt, ${skippedCount} übersprungen.`);
|
||||
this.logger.log(
|
||||
`Prüfung abgeschlossen. ${updatedCount} E-Mails aktualisiert, ${idsUpdated} Paperless-IDs ergänzt, ${skippedCount} übersprungen.`,
|
||||
);
|
||||
return { updatedCount, idsUpdated };
|
||||
} catch (error: any) {
|
||||
this.logger.error(`Kritischer Fehler bei checkAttachments: ${error.message}`, error.stack);
|
||||
this.logger.error(
|
||||
`Kritischer Fehler bei checkAttachments: ${error.message}`,
|
||||
error.stack,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user