Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import {
loadUnlock,
displayUnlock,
displayHint,
getSolution,
loadSolution,
displaySolution,
displayHintUnlock,
displaySolutionUnlock,
submitRating,
checkSolution,
} from "./pages/challenge";
import { getScoreboard, getScoreboardDetail, getBrackets } from "./pages/scoreboard";
import { updateSettings, generateToken, deleteToken } from "./pages/settings";
Expand Down Expand Up @@ -93,6 +95,9 @@ const _functions = {

// Display solves for challenge
displaySolves: null,

// Check whether UI should reach out for solution ID
checkSolution: null,
},

challenges: {
Expand Down Expand Up @@ -142,6 +147,8 @@ const pages = {
displayHintUnlock,
displaySolutionUnlock,
displayHint,
getSolution,
checkSolution,
loadSolution,
displaySolution,
submitRating,
Expand Down
28 changes: 28 additions & 0 deletions pages/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,34 @@ export async function displaySolves(challengeId) {
}
}

export async function getSolution(challengeId) {
const response = await CTFd.fetch(`/api/v1/challenges/${challengeId}/solution`, {
method: "GET",
});

const body = await response.json();
return body["data"];
}

// Function to check whether the UI should check for a challenge solution
export async function checkSolution(solutionState, challengeData, submissionStatus) {
if (CTFd._functions.challenge.checkSolution) {
return CTFd._functions.challenge.checkSolution(
solutionState,
challengeData,
submissionStatus
);
}
if (solutionState == "hidden" || solutionState == "visible") {
return false;
} else if (solutionState == "solved" && submissionStatus === "correct") {
Comment on lines +154 to +156
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent equality operators: use strict equality (===) for solutionState comparisons on line 154, matching the strict equality used for submissionStatus on line 156.

Suggested change
if (solutionState == "hidden" || solutionState == "visible") {
return false;
} else if (solutionState == "solved" && submissionStatus === "correct") {
if (solutionState === "hidden" || solutionState === "visible") {
return false;
} else if (solutionState === "solved" && submissionStatus === "correct") {

Copilot uses AI. Check for mistakes.
return true;
} else {
// We default to true in case there is a solution state that we are not aware of
return true;
}
}

export async function loadSolution(solutionId) {
const response = await CTFd.fetch(`/api/v1/solutions/${solutionId}`, {
method: "GET",
Expand Down