mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
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:
1 parent
c79a9636a7
commit
e7ad53643c
12 files changed
+855
-187
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { queryOne } from "@/lib/db";
|
||||
|
||||
export async function GET(request, context) {
|
||||
try {
|
||||
const token = await getToken({
|
||||
req: request,
|
||||
secret:
|
||||
process.env.NEXTAUTH_SECRET ||
|
||||
"your-fallback-secret-should-be-at-least-32-chars",
|
||||
});
|
||||
|
||||
if (!token) {
|
||||
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { teamId } = context.params;
|
||||
|
||||
// Validate that user belongs to this team
|
||||
if (!token.teamId || parseInt(token.teamId, 10) !== parseInt(teamId, 10)) {
|
||||
return Response.json(
|
||||
{ error: "You are not a member of this team" },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
|
||||
// Get the team's hunt session from the database
|
||||
const session = await queryOne(
|
||||
"SELECT team_id, start_time FROM team_hunt_sessions WHERE team_id = ?",
|
||||
[teamId]
|
||||
);
|
||||
|
||||
if (!session) {
|
||||
// Try to get the global hunt start time as fallback
|
||||
const huntStatus = await queryOne(
|
||||
"SELECT start_time FROM hunt_status WHERE is_active = 1 LIMIT 1"
|
||||
);
|
||||
if (huntStatus && huntStatus.start_time) {
|
||||
return Response.json({
|
||||
startTime: huntStatus.start_time,
|
||||
source: "global_hunt_status",
|
||||
});
|
||||
}
|
||||
|
||||
// Final fallback to settings table
|
||||
const huntActive = await queryOne(
|
||||
"SELECT value FROM settings WHERE key = 'hunt_active'"
|
||||
);
|
||||
if (huntActive && huntActive.value === "true") {
|
||||
return Response.json({
|
||||
startTime: new Date().toISOString(),
|
||||
source: "fallback_current_time",
|
||||
});
|
||||
}
|
||||
|
||||
return Response.json(
|
||||
{ error: "No hunt session found for this team" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return Response.json({
|
||||
teamId: session.team_id,
|
||||
startTime: session.start_time,
|
||||
source: "team_session",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Get team hunt session error:", error);
|
||||
return Response.json(
|
||||
{ error: "Failed to get hunt session: " + error.message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user