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

@@ -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) {