import { Controller, Post, Logger, HttpCode, HttpStatus } from '@nestjs/common'; import { RequirePermissions } from '../auth/permissions.decorator'; import { Permission } from '../auth/permissions.enum'; import { EmailDownloadService } from './email-download.service'; @Controller('api/emails') export class EmailDownloadController { private readonly logger = new Logger(EmailDownloadController.name); constructor(private readonly emailDownloadService: EmailDownloadService) {} @Post('fetch') @HttpCode(HttpStatus.OK) @RequirePermissions(Permission.VIEW_MAIL) async triggerFetch() { this.logger.log('Manueller E-Mail-Abruf wurde ausgelöst.'); await this.emailDownloadService.handleCron(); return { message: 'E-Mail-Abruf abgeschlossen.' }; } @Post('backfill-thumbnails') @RequirePermissions(Permission.MANAGE_ALL) @HttpCode(HttpStatus.OK) async backfillThumbnails() { this.logger.log('Manueller Backfill für Thumbnails wurde ausgelöst.'); const result = await this.emailDownloadService.backfillThumbnailsForNewEmails(); return { message: 'Backfill abgeschlossen.', result }; } }