feat: add configurable timezone for daily puzzle rotation with logging
This commit is contained in:
@@ -62,7 +62,9 @@ Das Projekt ist für den Betrieb mit Docker optimiert.
|
||||
```bash
|
||||
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:**
|
||||
```bash
|
||||
|
||||
@@ -5,13 +5,22 @@ const prisma = new PrismaClient();
|
||||
|
||||
export async function GET() {
|
||||
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({
|
||||
where: { date: today },
|
||||
include: { song: true },
|
||||
});
|
||||
|
||||
console.log(`[Daily Puzzle] Date: ${today}, Found existing: ${!!dailyPuzzle}`);
|
||||
|
||||
if (!dailyPuzzle) {
|
||||
// Get all songs with their usage count
|
||||
const allSongs = await prisma.song.findMany({
|
||||
@@ -54,6 +63,8 @@ export async function GET() {
|
||||
},
|
||||
include: { song: true },
|
||||
});
|
||||
|
||||
console.log(`[Daily Puzzle] Created new puzzle for ${today} with song: ${selectedSong.title} (ID: ${selectedSong.id})`);
|
||||
}
|
||||
|
||||
if (!dailyPuzzle) {
|
||||
@@ -63,7 +74,10 @@ export async function GET() {
|
||||
return NextResponse.json({
|
||||
id: dailyPuzzle.id,
|
||||
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) {
|
||||
|
||||
@@ -11,6 +11,7 @@ services:
|
||||
environment:
|
||||
- DATABASE_URL=file:/app/data/prod.db
|
||||
- ADMIN_PASSWORD=admin123 # Change this!
|
||||
- TZ=Europe/Berlin # Timezone for daily puzzle rotation
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./public/uploads:/app/public/uploads
|
||||
|
||||
Reference in New Issue
Block a user