Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Brackets support #23

Merged
merged 2 commits into from
Sep 7, 2024
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
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"];
}
Loading