Skip to content

Commit 90e7416

Browse files
authored
Add Brackets support (#23)
* Add `getBrackets` function to `CTFd.pages.scoreboard` and add `bracketId` argument to scoreboard functions * Closes #22
1 parent 65df4e0 commit 90e7416

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
displayUnlock,
1313
displayHint,
1414
} from "./pages/challenge";
15-
import { getScoreboard, getScoreboardDetail } from "./pages/scoreboard";
15+
import { getScoreboard, getScoreboardDetail, getBrackets } from "./pages/scoreboard";
1616
import { updateSettings, generateToken, deleteToken } from "./pages/settings";
1717
import { userSolves, userFails, userAwards } from "./pages/users";
1818
import {
@@ -136,6 +136,7 @@ const pages = {
136136
scoreboard: {
137137
getScoreboard,
138138
getScoreboardDetail,
139+
getBrackets,
139140
},
140141
settings: {
141142
updateSettings,

pages/scoreboard.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
import CTFd from "../main";
22

3-
export async function getScoreboard() {
4-
const response = await CTFd.fetch("/api/v1/scoreboard", {
3+
export async function getScoreboard(bracketId = null) {
4+
let url = "/api/v1/scoreboard";
5+
if (bracketId) {
6+
url = `${url}?bracket_id=${bracketId}`;
7+
}
8+
const response = await CTFd.fetch(url, {
59
method: "GET",
610
});
711
const body = await response.json();
812
return body["data"]; // scoreboard data
913
}
1014

11-
export async function getScoreboardDetail(count) {
12-
const response = await CTFd.fetch(`/api/v1/scoreboard/top/${count}`, {
15+
export async function getScoreboardDetail(count, bracketId = null) {
16+
let url = `/api/v1/scoreboard/top/${count}`;
17+
if (bracketId) {
18+
url = `${url}?bracket_id=${bracketId}`;
19+
}
20+
const response = await CTFd.fetch(url, {
1321
method: "GET",
1422
});
1523
const body = await response.json();
1624
return body["data"]; // scoreboard data
1725
}
26+
27+
export async function getBrackets(userMode) {
28+
const response = await CTFd.fetch(`/api/v1/brackets?type=${userMode}`, {
29+
method: "GET",
30+
});
31+
const body = await response.json();
32+
return body["data"];
33+
}

0 commit comments

Comments
 (0)