feat: add configurable timezone for daily puzzle rotation with logging

This commit is contained in:
Hördle Bot
2025-11-21 21:53:22 +01:00
parent 75a8a63b21
commit 3f47fac276
3 changed files with 20 additions and 3 deletions

View File

@@ -62,7 +62,9 @@ Das Projekt ist für den Betrieb mit Docker optimiert.
```bash ```bash
cp docker-compose.example.yml docker-compose.yml cp docker-compose.example.yml docker-compose.yml
``` ```
Passe ggf. das `ADMIN_PASSWORD` in der `docker-compose.yml` an. Passe die Umgebungsvariablen in der `docker-compose.yml` an:
- `ADMIN_PASSWORD`: Admin-Passwort (Standard: `admin123`)
- `TZ`: Zeitzone für täglichen Puzzle-Wechsel (Standard: `Europe/Berlin`)
2. **Starten:** 2. **Starten:**
```bash ```bash

View File

@@ -5,13 +5,22 @@ const prisma = new PrismaClient();
export async function GET() { export async function GET() {
try { try {
const today = new Date().toISOString().split('T')[0]; // Use timezone from environment variable (default: Europe/Berlin)
const timezone = process.env.TZ || 'Europe/Berlin';
const today = new Date().toLocaleDateString('en-CA', {
timeZone: timezone,
year: 'numeric',
month: '2-digit',
day: '2-digit'
}); // Format: "2025-11-21"
let dailyPuzzle = await prisma.dailyPuzzle.findUnique({ let dailyPuzzle = await prisma.dailyPuzzle.findUnique({
where: { date: today }, where: { date: today },
include: { song: true }, include: { song: true },
}); });
console.log(`[Daily Puzzle] Date: ${today}, Found existing: ${!!dailyPuzzle}`);
if (!dailyPuzzle) { if (!dailyPuzzle) {
// Get all songs with their usage count // Get all songs with their usage count
const allSongs = await prisma.song.findMany({ const allSongs = await prisma.song.findMany({
@@ -54,6 +63,8 @@ export async function GET() {
}, },
include: { song: true }, include: { song: true },
}); });
console.log(`[Daily Puzzle] Created new puzzle for ${today} with song: ${selectedSong.title} (ID: ${selectedSong.id})`);
} }
if (!dailyPuzzle) { if (!dailyPuzzle) {
@@ -63,7 +74,10 @@ export async function GET() {
return NextResponse.json({ return NextResponse.json({
id: dailyPuzzle.id, id: dailyPuzzle.id,
audioUrl: `/uploads/${dailyPuzzle.song.filename}`, audioUrl: `/uploads/${dailyPuzzle.song.filename}`,
songId: dailyPuzzle.songId songId: dailyPuzzle.songId,
title: dailyPuzzle.song.title,
artist: dailyPuzzle.song.artist,
coverImage: dailyPuzzle.song.coverImage ? `/uploads/covers/${dailyPuzzle.song.coverImage}` : null,
}); });
} catch (error) { } catch (error) {

View File

@@ -11,6 +11,7 @@ services:
environment: environment:
- DATABASE_URL=file:/app/data/prod.db - DATABASE_URL=file:/app/data/prod.db
- ADMIN_PASSWORD=admin123 # Change this! - ADMIN_PASSWORD=admin123 # Change this!
- TZ=Europe/Berlin # Timezone for daily puzzle rotation
volumes: volumes:
- ./data:/app/data - ./data:/app/data
- ./public/uploads:/app/public/uploads - ./public/uploads:/app/public/uploads