feat(api): add cache + busting for admin
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user