File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -11,11 +11,13 @@ import {
1111 loadUnlock ,
1212 displayUnlock ,
1313 displayHint ,
14+ getSolution ,
1415 loadSolution ,
1516 displaySolution ,
1617 displayHintUnlock ,
1718 displaySolutionUnlock ,
1819 submitRating ,
20+ checkSolution ,
1921} from "./pages/challenge" ;
2022import { getScoreboard , getScoreboardDetail , getBrackets } from "./pages/scoreboard" ;
2123import { updateSettings , generateToken , deleteToken } from "./pages/settings" ;
@@ -93,6 +95,9 @@ const _functions = {
9395
9496 // Display solves for challenge
9597 displaySolves : null ,
98+
99+ // Check whether UI should reach out for solution ID
100+ checkSolution : null ,
96101 } ,
97102
98103 challenges : {
@@ -142,6 +147,8 @@ const pages = {
142147 displayHintUnlock,
143148 displaySolutionUnlock,
144149 displayHint,
150+ getSolution,
151+ checkSolution,
145152 loadSolution,
146153 displaySolution,
147154 submitRating,
Original file line number Diff line number Diff line change @@ -133,6 +133,34 @@ export async function displaySolves(challengeId) {
133133 }
134134}
135135
136+ export async function getSolution ( challengeId ) {
137+ const response = await CTFd . fetch ( `/api/v1/challenges/${ challengeId } /solution` , {
138+ method : "GET" ,
139+ } ) ;
140+
141+ const body = await response . json ( ) ;
142+ return body [ "data" ] ;
143+ }
144+
145+ // Function to check whether the UI should check for a challenge solution
146+ export async function checkSolution ( solutionState , challengeData , submissionStatus ) {
147+ if ( CTFd . _functions . challenge . checkSolution ) {
148+ return CTFd . _functions . challenge . checkSolution (
149+ solutionState ,
150+ challengeData ,
151+ submissionStatus
152+ ) ;
153+ }
154+ if ( solutionState == "hidden" || solutionState == "visible" ) {
155+ return false ;
156+ } else if ( solutionState == "solved" && submissionStatus === "correct" ) {
157+ return true ;
158+ } else {
159+ // We default to true in case there is a solution state that we are not aware of
160+ return true ;
161+ }
162+ }
163+
136164export async function loadSolution ( solutionId ) {
137165 const response = await CTFd . fetch ( `/api/v1/solutions/${ solutionId } ` , {
138166 method : "GET" ,
You can’t perform that action at this time.
0 commit comments