refactor: simplify backup result handling
This commit is contained in:
@@ -107,15 +107,17 @@ type ScriptResult = {
|
||||
downloadFolders: string[]
|
||||
}
|
||||
|
||||
const selectedBackup = ref<string | null>(null)
|
||||
const scriptResult = ref<ScriptResult>({
|
||||
key: null as string | null,
|
||||
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
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user