mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-19 15:04:23 +01:00
Use new properties in /api/v1/challenges (#1844)
- Switch the challenges page in core to use the new API information in `/api/v1/challenges` to mark solves and display solve counts - Closes #1811
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
- Add styling for the `<blockquote>` element.
|
- Add styling for the `<blockquote>` element.
|
||||||
- Change `colorHash` function to use HSL color values to avoid generating too light/dark colors
|
- Change `colorHash` function to use HSL color values to avoid generating too light/dark colors
|
||||||
- Fix scoreboard table identifier to switch between User/Team depending on configured user mode
|
- Fix scoreboard table identifier to switch between User/Team depending on configured user mode
|
||||||
|
- Switch the challenges page in core to use the new API information in `/api/v1/challenges` to mark solves and display solve counts
|
||||||
- Switch to using Bootstrap's scss in `core/main.scss` to allow using Bootstrap variables
|
- Switch to using Bootstrap's scss in `core/main.scss` to allow using Bootstrap variables
|
||||||
- Consolidate Jinja error handlers into a single function and better handle issues where error templates can't be found
|
- Consolidate Jinja error handlers into a single function and better handle issues where error templates can't be found
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,6 @@ import hljs from "highlight.js";
|
|||||||
|
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
const api_func = {
|
|
||||||
teams: x => CTFd.api.get_team_solves({ teamId: x }),
|
|
||||||
users: x => CTFd.api.get_user_solves({ userId: x })
|
|
||||||
};
|
|
||||||
|
|
||||||
CTFd._internal.challenge = {};
|
CTFd._internal.challenge = {};
|
||||||
let challenges = [];
|
let challenges = [];
|
||||||
let solves = [];
|
let solves = [];
|
||||||
@@ -232,31 +227,15 @@ function renderSubmissionResponse(response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function markSolves() {
|
function markSolves() {
|
||||||
return api_func[CTFd.config.userMode]("me").then(function(response) {
|
challenges.map(challenge => {
|
||||||
const solves = response.data;
|
if (challenge.solved_by_me) {
|
||||||
for (let i = solves.length - 1; i >= 0; i--) {
|
const btn = $(`button[value="${challenge.id}"]`);
|
||||||
const btn = $('button[value="' + solves[i].challenge_id + '"]');
|
|
||||||
btn.addClass("solved-challenge");
|
btn.addClass("solved-challenge");
|
||||||
btn.prepend("<i class='fas fa-check corner-button-check'></i>");
|
btn.prepend("<i class='fas fa-check corner-button-check'></i>");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadUserSolves() {
|
|
||||||
if (CTFd.user.id == 0) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
return api_func[CTFd.config.userMode]("me").then(function(response) {
|
|
||||||
const solves = response.data;
|
|
||||||
|
|
||||||
for (let i = solves.length - 1; i >= 0; i--) {
|
|
||||||
const chal_id = solves[i].challenge_id;
|
|
||||||
solves.push(chal_id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSolves(id) {
|
function getSolves(id) {
|
||||||
return CTFd.api.get_challenge_solves({ challengeId: id }).then(response => {
|
return CTFd.api.get_challenge_solves({ challengeId: id }).then(response => {
|
||||||
const data = response.data;
|
const data = response.data;
|
||||||
@@ -289,7 +268,6 @@ function loadChals() {
|
|||||||
$challenges_board.empty();
|
$challenges_board.empty();
|
||||||
|
|
||||||
for (let i = challenges.length - 1; i >= 0; i--) {
|
for (let i = challenges.length - 1; i >= 0; i--) {
|
||||||
challenges[i].solves = 0;
|
|
||||||
if ($.inArray(challenges[i].category, categories) == -1) {
|
if ($.inArray(challenges[i].category, categories) == -1) {
|
||||||
const category = challenges[i].category;
|
const category = challenges[i].category;
|
||||||
categories.push(category);
|
categories.push(category);
|
||||||
@@ -354,15 +332,12 @@ function loadChals() {
|
|||||||
|
|
||||||
$(".challenge-button").click(function(_event) {
|
$(".challenge-button").click(function(_event) {
|
||||||
loadChal(this.value);
|
loadChal(this.value);
|
||||||
getSolves(this.value);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
return loadUserSolves() // Load the user's solved challenge ids
|
return loadChals().then(markSolves);
|
||||||
.then(loadChals) // Load the full list of challenges
|
|
||||||
.then(markSolves);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$(() => {
|
$(() => {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user