Skip to content

Commit

Permalink
Add getBrackets function to CTFd.pages.scoreboard and add bracketId a…
Browse files Browse the repository at this point in the history
…rgument to scoreboard functions
  • Loading branch information
ColdHeat committed Sep 7, 2024
1 parent 65df4e0 commit 753d5bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
displayUnlock,
displayHint,
} from "./pages/challenge";
import { getScoreboard, getScoreboardDetail } from "./pages/scoreboard";
import { getScoreboard, getScoreboardDetail, getBrackets } from "./pages/scoreboard";
import { updateSettings, generateToken, deleteToken } from "./pages/settings";
import { userSolves, userFails, userAwards } from "./pages/users";
import {
Expand Down Expand Up @@ -136,6 +136,7 @@ const pages = {
scoreboard: {
getScoreboard,
getScoreboardDetail,
getBrackets,
},
settings: {
updateSettings,
Expand Down
24 changes: 20 additions & 4 deletions pages/scoreboard.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import CTFd from "../main";

export async function getScoreboard() {
const response = await CTFd.fetch("/api/v1/scoreboard", {
export async function getScoreboard(bracketId = null) {
let url = "/api/v1/scoreboard";
if (bracketId) {
url = `${url}&bracket_id=${bracketId}`;
}
const response = await CTFd.fetch(url, {
method: "GET",
});
const body = await response.json();
return body["data"]; // scoreboard data
}

export async function getScoreboardDetail(count) {
const response = await CTFd.fetch(`/api/v1/scoreboard/top/${count}`, {
export async function getScoreboardDetail(count, bracketId = null) {
let url = `/api/v1/scoreboard/top/${count}`;
if (bracketId) {
url = `${url}&bracket_id=${bracketId}`;
}
const response = await CTFd.fetch(url, {
method: "GET",
});
const body = await response.json();
return body["data"]; // scoreboard data
}

export async function getBrackets(userMode) {
const response = await CTFd.fetch(`/api/v1/brackets?type=${userMode}`, {
method: "GET",
});
const body = await response.json();
return body["data"];
}

0 comments on commit 753d5bf

Please sign in to comment.