From 889d723e81fef5a1918dad0780b5773f7a41fe85 Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 10 Mar 2026 13:51:21 +0100 Subject: [PATCH] refactor: simplify backup result handling --- pages/backup.vue | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pages/backup.vue b/pages/backup.vue index 94cf418..5a03de5 100644 --- a/pages/backup.vue +++ b/pages/backup.vue @@ -107,15 +107,17 @@ type ScriptResult = { downloadFolders: string[] } -const selectedBackup = ref(null) -const scriptResult = ref({ - key: null as string | null, +const emptyScriptResult = (): ScriptResult => ({ + key: null, label: "", output: "", isError: false, downloadFolders: [] }) +const selectedBackup = ref(null) +const scriptResult = ref(emptyScriptResult()) + const fetchLatestBackup = async (folder: string) => { const files = await $fetch(`/api/backups?folder=${encodeURIComponent(folder)}`) return files[0] || null @@ -130,8 +132,16 @@ const triggerDownload = (folder: string, file: string) => { link.remove() } +const downloadLatestBackup = async (folder: string) => { + const latestFile = await fetchLatestBackup(folder) + + if (latestFile) { + triggerDownload(folder, latestFile) + } +} + const handleScriptResult = async (payload: ScriptResult) => { - scriptResult.value = payload + scriptResult.value = { ...emptyScriptResult(), ...payload } if (payload.isError || payload.downloadFolders.length === 0) { return @@ -139,10 +149,7 @@ const handleScriptResult = async (payload: ScriptResult) => { for (const folder of payload.downloadFolders) { try { - const latestFile = await fetchLatestBackup(folder) - if (latestFile) { - triggerDownload(folder, latestFile) - } + await downloadLatestBackup(folder) } catch (error) { console.error(`Erreur telechargement automatique pour ${folder}:`, error) }