Skip to content

Commit c2dbaf9

Browse files
authored
Add CTFd.pages.challenge.loadSolution and CTFd.pages.challenge.displaySolution (#27)
* Add `CTFd.pages.challenge.loadSolution` * Add `CTFd.pages.challenge.displaySolution`
1 parent 0bc56ad commit c2dbaf9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
loadUnlock,
1212
displayUnlock,
1313
displayHint,
14+
loadSolution,
15+
displaySolution,
1416
} from "./pages/challenge";
1517
import { getScoreboard, getScoreboardDetail, getBrackets } from "./pages/scoreboard";
1618
import { updateSettings, generateToken, deleteToken } from "./pages/settings";
@@ -127,6 +129,8 @@ const pages = {
127129
loadUnlock,
128130
displayUnlock,
129131
displayHint,
132+
loadSolution,
133+
displaySolution,
130134
},
131135
challenges: {
132136
getChallenges,

pages/challenge.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,19 @@ export async function displaySolves(challengeId) {
120120
CTFd._functions.challenge.displaySolves(solves);
121121
}
122122
}
123+
124+
export async function loadSolution(solutionId) {
125+
const response = await CTFd.fetch(`/api/v1/solutions/${solutionId}`, {
126+
method: "GET",
127+
});
128+
129+
const body = await response.json();
130+
return body["data"];
131+
}
132+
133+
export async function displaySolution(solutionId) {
134+
let solution = await loadSolution(solutionId);
135+
if (CTFd._functions.challenge.displaySolution) {
136+
CTFd._functions.challenge.displaySolution(solution);
137+
}
138+
}

0 commit comments

Comments
 (0)