logo first try, #20 cleanup, show today in blue deck-list
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user