feat(api): add cache + busting for admin

This commit is contained in:
2026-05-10 04:00:53 +02:00
parent 2264401a91
commit 5aeff9c218
11 changed files with 175 additions and 8 deletions
+31
View File
@@ -11,6 +11,7 @@ const userInfo = ref({
rank: null as number | null,
score: 0,
runsSubmitted: 0,
isStaff: false,
});
const uploadedFiles = ref<File[]>([]);
@@ -148,6 +149,30 @@ const fetchLeaderboard = async () => {
}
};
const clearCache = async () => {
try {
const response = await fetch("/api/cache/clear", {
method: "POST",
});
if (response.ok) {
alert("Cache cleared successfully!");
// Refresh data after clearing cache
await Promise.all([
fetchObjectives(),
fetchUserResults(),
fetchLeaderboard(),
]);
} else {
const error = await response.json();
alert(`Error clearing cache: ${error.detail || "Unknown error"}`);
}
} catch (error) {
console.error("Error clearing cache:", error);
alert("Error clearing cache. Please try again.");
}
};
const loadUserData = async () => {
// Get user info first
try {
@@ -156,6 +181,7 @@ const loadUserData = async () => {
const user = await response.json();
if (user.is_authenticated) {
userInfo.value.username = user.username;
userInfo.value.isStaff = user.is_staff || false;
}
}
} catch (error) {
@@ -237,6 +263,11 @@ onMounted(() => {
<i class="mdi mdi-trophy mr-1"></i>
View Full Leaderboard
</button>
<button v-if="userInfo.isStaff" @click="clearCache" class="btn btn-error btn-sm w-full mt-3">
<i class="mdi mdi-cache-clear mr-1"></i>
Clear Cache
</button>
</div>
</div>
</div>
@@ -50,6 +50,7 @@ const userInfo = ref({
rank: null as number | null,
totalPoints: 0,
puzzlesSolved: 0,
isStaff: false,
});
const fetchResults = async () => {
@@ -106,6 +107,25 @@ const togglePuzzleExpanded = (puzzleId: number) => {
expandedPuzzleId.value = expandedPuzzleId.value === puzzleId ? null : puzzleId;
};
const clearCache = async () => {
try {
const response = await fetch("/api/cache/clear", {
method: "POST",
});
if (response.ok) {
alert("Cache cleared successfully!");
await fetchResults();
} else {
const error = await response.json();
alert(`Error clearing cache: ${error.detail || "Unknown error"}`);
}
} catch (error) {
console.error("Error clearing cache:", error);
alert("Error clearing cache. Please try again.");
}
};
const loadUserData = async () => {
try {
const response = await fetch("/api/user");
@@ -113,6 +133,7 @@ const loadUserData = async () => {
const user = await response.json();
if (user.is_authenticated) {
userInfo.value.username = user.username;
userInfo.value.isStaff = user.is_staff || false;
await fetchResults();
@@ -178,6 +199,11 @@ onMounted(() => {
<p class="text-sm text-base-content/70 mb-1">Puzzles Solved</p>
<p class="text-2xl font-bold">{{ userInfo.puzzlesSolved }}</p>
</div>
<button v-if="userInfo.isStaff" @click="clearCache" class="btn btn-error btn-sm w-full mt-6">
<i class="mdi mdi-cache-clear mr-1"></i>
Clear Cache
</button>
</div>
</div>
</div>