issues regarding the map and hunt stopping have been fixed. leaderboard page needs to be integrated and a clues should be added to be properly processed. after that the css for the application should be developed.

This commit is contained in:
bobbert committed 2025-03-15 01:10:05 +00:00
1 parent c79a9636a7
commit e7ad53643c
12 files changed
+855 -187

No files matched your search

+47 -41
View File
@@ -1,6 +1,4 @@
import { queryOne, run } from "@/lib/db";
import { cookies } from "next/headers";
import { verifyToken } from "@/app/api/auth/[...nextauth]/route";
export const dynamic = "force-dynamic"; // Disable caching
@@ -33,68 +31,76 @@ async function ensureHuntStatusTableExists() {
}
}
// GET endpoint to check if the hunt is active
// GET endpoint to check if the hunt is active - allow unauthenticated access for easier status checks
export async function GET(request) {
try {
// First ensure the table exists
await ensureHuntStatusTableExists();
// Get the token from cookies - properly awaited
const cookieStore = await cookies();
const sessionToken = cookieStore.get("next-auth.session-token")?.value;
// NO TOKEN CHECK - Allow anonymous status checks
// This is critical for the waiting page to work reliably
// Check hunt status even if user is not authenticated
// to prevent auth errors from interfering with status checks
// First check the hunt_status table for direct status
// Query all possible sources
const huntStatus = await queryOne(
"SELECT is_active, start_time FROM hunt_status LIMIT 1"
).catch((err) => {
console.warn("Error querying hunt_status:", err.message);
return null;
});
).catch(() => null);
const timerStatus = await queryOne(
"SELECT active, start_time, end_time FROM hunt_timer WHERE active = 1 ORDER BY id DESC LIMIT 1"
).catch(() => null);
// Then check the settings table as a backup
const huntActiveSetting = await queryOne(
"SELECT value FROM settings WHERE key = 'hunt_active'"
).catch((err) => {
console.warn("Error querying settings:", err.message);
return null;
});
).catch(() => null);
// Also check the hunts table if it exists (for backward compatibility)
// Also check the traditional hunts table
const oldHuntRecord = await queryOne(
"SELECT active, start_time FROM hunts ORDER BY id DESC LIMIT 1"
).catch((err) => {
// Ignore errors if table doesn't exist
return null;
});
).catch(() => null);
// Determine active status from all available sources
// Determine active status from all possible sources
let isActive = false;
let startTime = null;
let endTime = null;
// First priority: hunt_status.is_active
if (huntStatus && huntStatus.is_active !== null) {
isActive = Boolean(huntStatus.is_active);
// Check all possible active indicators in priority order
if (timerStatus && Number(timerStatus.active) === 1) {
console.log("Hunt active from timer table");
isActive = true;
startTime = timerStatus.start_time;
endTime = timerStatus.end_time;
} else if (huntStatus && huntStatus.is_active) {
console.log("Hunt active from hunt_status table");
isActive = true;
startTime = huntStatus.start_time;
}
// Second priority: settings table
else if (huntActiveSetting) {
isActive = huntActiveSetting.value === "true";
}
// Third priority: old hunts table
else if (oldHuntRecord) {
isActive = Boolean(oldHuntRecord.active);
} else if (huntActiveSetting && huntActiveSetting.value === "true") {
console.log("Hunt active from settings table");
isActive = true;
} else if (oldHuntRecord && oldHuntRecord.active) {
console.log("Hunt active from hunts table");
isActive = true;
startTime = oldHuntRecord.start_time;
}
console.log("Hunt status check:", { isActive, startTime });
console.log("Hunt status check:", { isActive, startTime, endTime });
return Response.json({
active: isActive,
startTime: startTime || null,
});
// Set extremely aggressive cache control headers
return new Response(
JSON.stringify({
active: isActive,
startTime: startTime || null,
endTime: endTime || null,
}),
{
status: 200,
headers: {
"Content-Type": "application/json",
"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0",
Pragma: "no-cache",
Expires: "0",
},
}
);
} catch (error) {
console.error("Error checking hunt status:", error);
return Response.json(