2025-09-10 14:28:38 +02:00
|
|
|
<template>
|
2025-09-24 09:13:04 +02:00
|
|
|
<div id="refresh-cache-button">
|
|
|
|
|
<k-button
|
|
|
|
|
v-if="pageStatus !== 'draft'"
|
|
|
|
|
:theme="theme"
|
|
|
|
|
variant="dimmed"
|
|
|
|
|
:icon="icon"
|
|
|
|
|
:title="title"
|
|
|
|
|
@click="refreshCache()"
|
|
|
|
|
>{{ text }}</k-button
|
|
|
|
|
>
|
|
|
|
|
</div>
|
2025-09-10 14:28:38 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-09-24 09:13:04 +02:00
|
|
|
import { computed, ref } from "vue";
|
2025-09-10 14:28:38 +02:00
|
|
|
|
2025-09-24 09:13:04 +02:00
|
|
|
const { pageUri, pageStatus, lastCacheUpdate } = defineProps({
|
2025-09-10 14:28:38 +02:00
|
|
|
pageUri: String,
|
|
|
|
|
pageStatus: String,
|
2025-09-24 09:13:04 +02:00
|
|
|
lastCacheUpdate: String,
|
2025-09-10 14:28:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const text = ref("Rafraîchir");
|
|
|
|
|
const icon = ref("refresh");
|
|
|
|
|
const theme = ref("aqua-icon");
|
2025-09-24 09:13:04 +02:00
|
|
|
const title = computed(() => {
|
|
|
|
|
return lastCacheUpdate?.length > 0
|
|
|
|
|
? "Dernière mise à jour : " + lastCacheUpdate
|
|
|
|
|
: "Mettre à jour le cache front";
|
|
|
|
|
});
|
2025-09-10 14:28:38 +02:00
|
|
|
|
|
|
|
|
async function refreshCache() {
|
|
|
|
|
text.value = "En cours…";
|
|
|
|
|
icon.value = "loader";
|
|
|
|
|
theme.value = "orange-icon";
|
|
|
|
|
|
|
|
|
|
const init = {
|
|
|
|
|
method: "POST",
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
body: JSON.stringify({ pageUri }),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await fetch("/refresh-cache.json", init);
|
|
|
|
|
const json = await res.json();
|
|
|
|
|
|
|
|
|
|
if (json.status === "error") {
|
|
|
|
|
console.error(json);
|
|
|
|
|
text.value = "Erreur";
|
|
|
|
|
icon.value = "alert";
|
|
|
|
|
theme.value = "red-icon";
|
|
|
|
|
} else {
|
|
|
|
|
console.log(json);
|
|
|
|
|
text.value = "Terminé";
|
|
|
|
|
icon.value = "check";
|
|
|
|
|
theme.value = "green-icon";
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
2025-09-24 09:13:04 +02:00
|
|
|
location.href = location.href;
|
|
|
|
|
}, 1500);
|
2025-09-10 14:28:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|