Merge pull request 'fix/backup-ui-download' (#8) from fix/backup-ui-download into develop
All checks were successful
Release / release (push) Successful in 25s
All checks were successful
Release / release (push) Successful in 25s
Reviewed-on: #8
This commit was merged in pull request #8.
This commit is contained in:
@@ -1,15 +1,31 @@
|
||||
<template>
|
||||
<div class="backup-card card-glow">
|
||||
<div
|
||||
class="backup-card card-glow"
|
||||
:class="{
|
||||
'card-glow-success': message && !isError,
|
||||
'card-glow-error': message && isError
|
||||
}"
|
||||
>
|
||||
<div class="card-header">
|
||||
<h2 class="card-title">Run Script</h2>
|
||||
<span class="font-mono text-[10px] text-m-muted tracking-widest uppercase">Scripts</span>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="status-box">
|
||||
<div
|
||||
v-if="loading"
|
||||
class="status-box"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-busy="true"
|
||||
>
|
||||
Chargement des scripts...
|
||||
</div>
|
||||
|
||||
<div v-else class="backup-list">
|
||||
<div
|
||||
v-else-if="scripts.length"
|
||||
class="backup-list"
|
||||
:aria-busy="runningKey !== null"
|
||||
>
|
||||
<button
|
||||
v-for="item in scripts"
|
||||
:key="item.key"
|
||||
@@ -17,6 +33,8 @@
|
||||
class="backup-btn"
|
||||
:class="{ 'backup-btn-active': active === item.key }"
|
||||
:disabled="runningKey !== null"
|
||||
:aria-pressed="active === item.key"
|
||||
:aria-label="`Executer ${item.label}`"
|
||||
@click="runScript(item.key)"
|
||||
>
|
||||
<div class="flex items-center gap-2.5">
|
||||
@@ -36,10 +54,25 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="message" class="status-box" :class="statusClass">
|
||||
<p class="status-title">{{ message }}</p>
|
||||
<pre v-if="output" class="status-output">{{ output }}</pre>
|
||||
<div
|
||||
v-else
|
||||
class="status-box status-empty"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
Aucun script disponible.
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="message"
|
||||
class="status-box"
|
||||
:class="statusClass"
|
||||
role="status"
|
||||
:aria-live="isError ? 'assertive' : 'polite'"
|
||||
>
|
||||
<p class="status-title">{{ message }}</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -51,6 +84,7 @@ type BackupScript = {
|
||||
key: string
|
||||
label: string
|
||||
icon: string
|
||||
downloadFolders?: string[]
|
||||
}
|
||||
|
||||
type BackupScriptListResponse = {
|
||||
@@ -61,27 +95,58 @@ type BackupScriptRunResponse = {
|
||||
ok: boolean
|
||||
key: string
|
||||
label: string
|
||||
downloadFolders?: string[]
|
||||
output: string
|
||||
}
|
||||
|
||||
type ScriptResult = {
|
||||
key: string | null
|
||||
label: string
|
||||
output: string
|
||||
isError: boolean
|
||||
downloadFolders: string[]
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
result: [payload: ScriptResult]
|
||||
}>()
|
||||
|
||||
const active = ref<string | null>(null)
|
||||
const loading = ref(true)
|
||||
const runningKey = ref<string | null>(null)
|
||||
const scripts = ref<BackupScript[]>([])
|
||||
const output = ref("")
|
||||
const message = ref("")
|
||||
const output = ref<string>("")
|
||||
const message = ref<string>("")
|
||||
const isError = ref(false)
|
||||
|
||||
const statusClass = computed(() => (isError.value ? "status-error" : "status-success"))
|
||||
|
||||
const loadScripts = async () => {
|
||||
loading.value = true
|
||||
message.value = ""
|
||||
output.value = ""
|
||||
isError.value = false
|
||||
emit("result", {
|
||||
key: null,
|
||||
label: "",
|
||||
output: "",
|
||||
isError: false,
|
||||
downloadFolders: []
|
||||
})
|
||||
try {
|
||||
const data = await $fetch<BackupScriptListResponse>("/api/backup-script")
|
||||
scripts.value = data.scripts
|
||||
} catch (error) {
|
||||
scripts.value = []
|
||||
isError.value = true
|
||||
message.value = `Erreur chargement scripts: ${error instanceof Error ? error.message : String(error)}`
|
||||
emit("result", {
|
||||
key: null,
|
||||
label: "",
|
||||
output: "",
|
||||
isError: true,
|
||||
downloadFolders: []
|
||||
})
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -99,12 +164,26 @@ const runScript = async (key: string) => {
|
||||
method: "POST",
|
||||
body: { key }
|
||||
})
|
||||
message.value = `${data.label} execute`
|
||||
output.value = data.output
|
||||
message.value = `${data.label} execute avec succes`
|
||||
output.value = data.output || "Aucune sortie retournee."
|
||||
emit("result", {
|
||||
key: data.key,
|
||||
label: data.label,
|
||||
output: output.value,
|
||||
isError: false,
|
||||
downloadFolders: data.downloadFolders || []
|
||||
})
|
||||
} catch (error: any) {
|
||||
isError.value = true
|
||||
message.value = error?.data?.statusMessage || "Erreur execution script"
|
||||
output.value = ""
|
||||
emit("result", {
|
||||
key,
|
||||
label: scripts.value.find((item) => item.key === key)?.label || key,
|
||||
output: "",
|
||||
isError: true,
|
||||
downloadFolders: []
|
||||
})
|
||||
} finally {
|
||||
runningKey.value = null
|
||||
}
|
||||
@@ -154,6 +233,11 @@ onMounted(loadScripts)
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.backup-btn:focus-visible {
|
||||
outline: 2px solid rgb(var(--m-accent) / 0.7);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.backup-btn:disabled {
|
||||
cursor: wait;
|
||||
opacity: 0.7;
|
||||
@@ -188,14 +272,12 @@ onMounted(loadScripts)
|
||||
border: 1px solid rgb(255 99 99 / 0.3);
|
||||
}
|
||||
|
||||
.status-title {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.status-output {
|
||||
margin: 0.75rem 0 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
.status-empty {
|
||||
color: rgb(var(--m-muted));
|
||||
}
|
||||
|
||||
.status-title {
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
|
||||
289
pages/backup.vue
289
pages/backup.vue
@@ -23,6 +23,7 @@
|
||||
<BackupRun
|
||||
class="animate-fade-in-up"
|
||||
style="animation-delay: 180ms"
|
||||
@result="handleScriptResult"
|
||||
/>
|
||||
</section>
|
||||
|
||||
@@ -45,6 +46,47 @@
|
||||
:folder="selectedBackup"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<section
|
||||
class="files-panel output-panel animate-fade-in-up"
|
||||
style="animation-delay: 300ms"
|
||||
aria-labelledby="backup-output-title"
|
||||
>
|
||||
<div class="files-panel-header">
|
||||
<div>
|
||||
<p class="section-kicker">Execution</p>
|
||||
<h2 id="backup-output-title" class="files-panel-title">Resultat du script</h2>
|
||||
</div>
|
||||
<span
|
||||
class="panel-badge"
|
||||
:class="{
|
||||
'panel-badge-idle': !scriptResult.label,
|
||||
'panel-badge-success': scriptResult.label && !scriptResult.isError,
|
||||
'panel-badge-error': scriptResult.isError
|
||||
}"
|
||||
>
|
||||
{{ scriptResult.label || "Pret" }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="!scriptResult.output"
|
||||
class="output-empty"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>
|
||||
<p class="output-empty-title">Aucune sortie disponible</p>
|
||||
<p class="output-empty-text">
|
||||
Lancez un script depuis le panneau de gauche pour afficher son retour ici.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<pre
|
||||
v-else
|
||||
class="output-console"
|
||||
:class="{ 'output-console-error': scriptResult.isError }"
|
||||
>{{ scriptResult.output }}</pre>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
@@ -57,7 +99,62 @@ import BackupRun from "~/components/BackupRun.vue"
|
||||
|
||||
definePageMeta({ layout: false })
|
||||
|
||||
type ScriptResult = {
|
||||
key: string | null
|
||||
label: string
|
||||
output: string
|
||||
isError: boolean
|
||||
downloadFolders: string[]
|
||||
}
|
||||
|
||||
const emptyScriptResult = (): ScriptResult => ({
|
||||
key: null,
|
||||
label: "",
|
||||
output: "",
|
||||
isError: false,
|
||||
downloadFolders: []
|
||||
})
|
||||
|
||||
const selectedBackup = ref<string | null>(null)
|
||||
const scriptResult = ref<ScriptResult>(emptyScriptResult())
|
||||
|
||||
const fetchLatestBackup = async (folder: string) => {
|
||||
const files = await $fetch<string[]>(`/api/backups?folder=${encodeURIComponent(folder)}`)
|
||||
return files[0] || null
|
||||
}
|
||||
|
||||
const triggerDownload = (folder: string, file: string) => {
|
||||
const link = document.createElement("a")
|
||||
link.href = `/api/download?folder=${encodeURIComponent(folder)}&file=${encodeURIComponent(file)}`
|
||||
link.style.display = "none"
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
}
|
||||
|
||||
const downloadLatestBackup = async (folder: string) => {
|
||||
const latestFile = await fetchLatestBackup(folder)
|
||||
|
||||
if (latestFile) {
|
||||
triggerDownload(folder, latestFile)
|
||||
}
|
||||
}
|
||||
|
||||
const handleScriptResult = async (payload: ScriptResult) => {
|
||||
scriptResult.value = { ...emptyScriptResult(), ...payload }
|
||||
|
||||
if (payload.isError || payload.downloadFolders.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
for (const folder of payload.downloadFolders) {
|
||||
try {
|
||||
await downloadLatestBackup(folder)
|
||||
} catch (error) {
|
||||
console.error(`Erreur telechargement automatique pour ${folder}:`, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -93,108 +190,6 @@ const selectedBackup = ref<string | null>(null)
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.selection-card {
|
||||
padding: 1.25rem;
|
||||
border-radius: 16px;
|
||||
background:
|
||||
linear-gradient(180deg, rgb(var(--m-secondary)), rgb(var(--m-tertiary)));
|
||||
}
|
||||
|
||||
.selection-label {
|
||||
margin: 0;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.7rem;
|
||||
letter-spacing: 0.16em;
|
||||
text-transform: uppercase;
|
||||
color: rgb(var(--m-muted));
|
||||
}
|
||||
|
||||
.selection-value {
|
||||
margin: 0.65rem 0 0;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.selection-description {
|
||||
margin: 0.5rem 0 0;
|
||||
color: rgb(var(--m-muted));
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.intro-panel {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
margin-bottom: 1.5rem;
|
||||
padding: 1.5rem;
|
||||
border-radius: 20px;
|
||||
background:
|
||||
radial-gradient(circle at top right, rgb(var(--m-accent) / 0.12), transparent 28%),
|
||||
linear-gradient(180deg, rgb(var(--m-secondary)), rgb(var(--m-secondary) / 0.82));
|
||||
}
|
||||
|
||||
.intro-panel::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||
border-radius: inherit;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.intro-title {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
font-size: clamp(1.5rem, 2.2vw, 2rem);
|
||||
font-weight: 700;
|
||||
line-height: 1.15;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.intro-description {
|
||||
max-width: 68ch;
|
||||
margin: 0.85rem 0 0;
|
||||
color: rgb(var(--m-muted));
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.workflow-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 1rem;
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
.workflow-step {
|
||||
padding: 1rem;
|
||||
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||
border-radius: 16px;
|
||||
background: rgb(var(--m-bg) / 0.24);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.workflow-index {
|
||||
display: inline-block;
|
||||
margin-bottom: 0.75rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.75rem;
|
||||
letter-spacing: 0.16em;
|
||||
color: rgb(var(--m-accent));
|
||||
}
|
||||
|
||||
.workflow-title {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.workflow-text {
|
||||
margin: 0.45rem 0 0;
|
||||
color: rgb(var(--m-muted));
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.dashboard-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 300px minmax(0, 1fr);
|
||||
@@ -217,6 +212,10 @@ const selectedBackup = ref<string | null>(null)
|
||||
border: 1px solid rgb(var(--m-accent) / 0.08);
|
||||
}
|
||||
|
||||
.output-panel {
|
||||
min-height: 220px;
|
||||
}
|
||||
|
||||
.files-panel-header {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
@@ -243,10 +242,86 @@ const selectedBackup = ref<string | null>(null)
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.panel-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
border-radius: 999px;
|
||||
padding: 0.35rem 0.7rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.68rem;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.panel-badge-idle {
|
||||
color: rgb(var(--m-muted));
|
||||
background: rgb(var(--m-tertiary) / 0.45);
|
||||
border-color: rgb(var(--m-border) / 0.25);
|
||||
}
|
||||
|
||||
.panel-badge-success {
|
||||
color: rgb(var(--m-success));
|
||||
background: rgb(var(--m-success) / 0.08);
|
||||
border-color: rgb(var(--m-success) / 0.18);
|
||||
}
|
||||
|
||||
.panel-badge-error {
|
||||
color: rgb(var(--m-error));
|
||||
background: rgb(var(--m-error) / 0.08);
|
||||
border-color: rgb(var(--m-error) / 0.18);
|
||||
}
|
||||
|
||||
.output-empty {
|
||||
display: flex;
|
||||
min-height: 132px;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
border-radius: 14px;
|
||||
border: 1px dashed rgb(var(--m-border) / 0.55);
|
||||
background: rgb(var(--m-tertiary) / 0.38);
|
||||
padding: 1.25rem;
|
||||
}
|
||||
|
||||
.output-empty-title {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
font-size: 1rem;
|
||||
font-weight: 700;
|
||||
color: rgb(var(--m-text));
|
||||
}
|
||||
|
||||
.output-empty-text {
|
||||
margin: 0.5rem 0 0;
|
||||
max-width: 52ch;
|
||||
color: rgb(var(--m-muted));
|
||||
line-height: 1.65;
|
||||
}
|
||||
|
||||
.output-console {
|
||||
margin: 0;
|
||||
min-height: 132px;
|
||||
overflow-x: auto;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgb(var(--m-border) / 0.3);
|
||||
background:
|
||||
linear-gradient(180deg, rgb(var(--m-bg) / 0.96), rgb(var(--m-secondary) / 0.92));
|
||||
padding: 1rem 1.1rem;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.78rem;
|
||||
line-height: 1.7;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
color: rgb(var(--m-success));
|
||||
}
|
||||
|
||||
.output-console-error {
|
||||
color: rgb(var(--m-error));
|
||||
}
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
.dashboard-header,
|
||||
.dashboard-grid,
|
||||
.workflow-grid {
|
||||
.dashboard-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@@ -265,14 +340,8 @@ const selectedBackup = ref<string | null>(null)
|
||||
padding: 4.5rem 1.25rem 1.25rem;
|
||||
}
|
||||
|
||||
.intro-panel,
|
||||
.selection-card,
|
||||
.files-panel {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.workflow-grid {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -4,15 +4,17 @@ type BackupScript = {
|
||||
key: string
|
||||
label: string
|
||||
icon?: string
|
||||
downloadFolders?: string[]
|
||||
command: string
|
||||
}
|
||||
|
||||
export default defineEventHandler(() => {
|
||||
return {
|
||||
scripts: (scripts as BackupScript[]).map(({ key, label, icon }) => ({
|
||||
scripts: (scripts as BackupScript[]).map(({ key, label, icon, downloadFolders }) => ({
|
||||
key,
|
||||
label,
|
||||
icon: icon || "mdi:play-circle-outline"
|
||||
icon: icon || "mdi:play-circle-outline",
|
||||
downloadFolders: downloadFolders || []
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import scripts from "../config/backup-script.json"
|
||||
type BackupScript = {
|
||||
key: string
|
||||
label: string
|
||||
downloadFolders?: string[]
|
||||
command: string
|
||||
}
|
||||
|
||||
@@ -44,6 +45,7 @@ export default defineEventHandler(async (event) => {
|
||||
ok: true,
|
||||
key: script.key,
|
||||
label: script.label,
|
||||
downloadFolders: script.downloadFolders || [],
|
||||
output: output.trim()
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -3,18 +3,20 @@
|
||||
"key": "backup-bdd-recette",
|
||||
"label": "Backup BDD recette",
|
||||
"icon": "mdi:database-export",
|
||||
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/RecetteScripts && bash backup-bdd-recette.sh && exit'"
|
||||
"downloadFolders": ["ferme", "inventory", "sirh", "user"],
|
||||
"command": "ssh ferme 'cd /home/malio/Malio-ops/RecetteScripts && bash backup-bdd-recette.sh && exit'"
|
||||
},
|
||||
{
|
||||
"key": "check-statut-recette",
|
||||
"label": "Check statut recette",
|
||||
"icon": "mdi:server-network",
|
||||
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/RecetteScripts && bash check-statut-recette.sh && exit'"
|
||||
"command": "ssh ferme 'cd /home/malio/Malio-ops/RecetteScripts && bash check-statut-recette.sh && exit'"
|
||||
},
|
||||
{
|
||||
"key": "backup-vaultwarden",
|
||||
"label": "Backup vaultwarden",
|
||||
"icon": "mdi:data",
|
||||
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/BackupVaultWarden && bash backup-vaultwarden.sh && exit'"
|
||||
"downloadFolders": ["bitwarden"],
|
||||
"command": "ssh bitwarden 'cd /home/matt/vaultwarden/Malio-ops/BackupVaultWarden && bash backup-vaultwarden.sh && exit'"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
"key": "remote",
|
||||
"label": "Serveur distant",
|
||||
"command": "ssh malio-b@192.168.0.179 'cd /home/malio-b/Malio-ops/CheckStorage && bash check-storage.sh && exit'"
|
||||
"command": "ssh malio-b 'cd /home/malio-b/Malio-ops/CheckStorage && bash check-storage.sh && exit'"
|
||||
},
|
||||
{
|
||||
"key": "local",
|
||||
|
||||
Reference in New Issue
Block a user