logo first try, #20 cleanup, show today in blue deck-list

This commit is contained in:
Your Name
2025-01-31 19:01:10 +01:00
parent 2885ece241
commit ae9017020c
10 changed files with 151 additions and 55 deletions

View File

@@ -249,4 +249,21 @@ export class DrizzleService {
return { status: 'success' };
}
/**
* Methode zum Abrufen aller eindeutigen Bild-IDs aus der Datenbank
*/
async getDistinctBildIds(user: User): Promise<string[]> {
try {
const result = await this.db.selectDistinct([Deck.bildid]).from(Deck).all();
// Extrahiere die bildid Werte aus dem Ergebnis
const usedIds = result.map((row: any) => row['0']).filter((id: string | null) => id !== null) as string[];
console.log(usedIds);
return usedIds;
} catch (error) {
this.sqlLogger.logQuery('Error fetching distinct bildids', []);
throw new HttpException(`Fehler beim Abrufen der Bild-IDs - ${error}`, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@@ -2,11 +2,12 @@
import { Body, Controller, HttpException, HttpStatus, Post, Res, UseGuards } from '@nestjs/common';
import express from 'express';
import { AuthGuard } from '../service/auth.guard';
import { DrizzleService } from './drizzle.service';
@Controller('')
@UseGuards(AuthGuard)
export class ProxyController {
constructor() {}
constructor(private readonly drizzleService: DrizzleService) {}
// --------------------
// Proxy Endpoints
// --------------------
@@ -54,4 +55,50 @@ export class ProxyController {
throw new HttpException('Internal server error', HttpStatus.INTERNAL_SERVER_ERROR);
}
}
// --------------------
// Cleanup Endpoint
// --------------------
@Post('cleanup')
async cleanupEndpoint(@Body() data: { dryrun?: boolean }, @Res() res: express.Response) {
try {
const user = res.req['user']; // Benutzerinformationen aus dem Request
// 2. Nur Benutzer mit der spezifischen E-Mail dürfen fortfahren
if (user.email !== 'andreas.knuth@gmail.com') {
throw new HttpException('Zugriff verweigert.', HttpStatus.FORBIDDEN);
}
// 1. Abrufen der distinct bildid aus der Datenbank
const usedIds = await this.drizzleService.getDistinctBildIds(user);
// 3. Verarbeitung des dryrun Parameters
const dryrun = data.dryrun !== undefined ? data.dryrun : true;
if (typeof dryrun !== 'boolean') {
throw new HttpException("'dryrun' muss ein boolescher Wert sein.", HttpStatus.BAD_REQUEST);
}
// 4. Aufruf des Flask-Backend-Endpunkts
const response = await fetch('http://localhost:5000/api/cleanup', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ dryrun, usedIds }),
});
const result = await response.json();
if (!response.ok) {
throw new HttpException(result.error || 'Cleanup failed', response.status);
}
// 5. Rückgabe der Ergebnisse an den Client
return res.status(HttpStatus.OK).json(result);
} catch (error) {
if (error instanceof HttpException) {
throw error;
}
throw new HttpException('Interner Serverfehler', HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}