diff --git a/app/src/views/backup/BackupInfo.vue b/app/src/views/backup/BackupInfo.vue index 47ee2b19..41981df4 100644 --- a/app/src/views/backup/BackupInfo.vue +++ b/app/src/views/backup/BackupInfo.vue @@ -7,10 +7,11 @@ import api from '@/api' import { APIBadRequestError, type APIError } from '@/api/errors' import { useAutoModal } from '@/composables/useAutoModal' import { useInfos } from '@/composables/useInfos' -import { useInitialQueries } from '@/composables/useInitialQueries' import { isEmptyValue } from '@/helpers/commons' import { readableDate } from '@/helpers/filters/date' import { humanSize } from '@/helpers/filters/human' +import type { BackupInfo } from '@/types/core/api' +import { formatBackupSystem, parseBackupForm } from './backupData' const props = defineProps<{ id: string @@ -20,63 +21,33 @@ const props = defineProps<{ const { t } = useI18n() const router = useRouter() const modalConfirm = useAutoModal() -const { loading } = useInitialQueries( - [{ uri: `backups/${props.name}?with_details` }], - { onQueriesResponse }, -) -const selected = ref([]) -const error = ref('') -const isValid = ref(null) -const infos = ref() -const apps = ref() -const system = ref() - -const hasBackupData = computed(() => { - return !isEmptyValue(system.value) || !isEmptyValue(apps.value) -}) - -function formatHooks(hooks) { - const data = {} - Object.entries(hooks).forEach(([hook, { size }]) => { - const groupId = hook.startsWith('conf_') - ? 'adminjs_group_configuration' - : hook - if (groupId in data) { - data[groupId].value.push(hook) - data[groupId].description += ', ' + t('hook_' + hook) - data[groupId].size += size - } else { - data[groupId] = { - name: t('hook_' + groupId), - value: [hook], - description: t(groupId === hook ? `hook_${hook}_desc` : 'hook_' + hook), - size, - } +const { infos, system, apps } = await api + .get({ uri: `backups/${props.name}?with_details` }) + .then((backup) => { + return { + system: formatBackupSystem(backup.system), + apps: backup.apps, + infos: { + id: props.name, + created_at: readableDate(backup.created_at), + size: humanSize(backup.size), + path: backup.path, + }, } }) - return data -} -function onQueriesResponse(data: any) { - infos.value = { - name: props.name, - created_at: data.created_at, - size: data.size, - path: data.path, - } - system.value = formatHooks(data.system) - apps.value = data.apps +const allKeys = [...Object.keys(apps), ...Object.keys(system)] +const selected = ref(allKeys) +const serverError = ref('') +const isValid = ref(null) - toggleSelected() -} +const hasBackupData = computed(() => { + return !isEmptyValue(system) || !isEmptyValue(apps) +}) function toggleSelected(select = true) { - if (select) { - selected.value = [...Object.keys(apps.value), ...Object.keys(system.value)] - } else { - selected.value = [] - } + selected.value = select ? allKeys : [] } async function restoreBackup() { @@ -85,19 +56,12 @@ async function restoreBackup() { ) if (!confirmed) return - const data = { apps: [], system: [], force: '' } - for (const item of selected.value) { - if (item in system.value) { - data.system = [...data.system, ...system.value[item].value] - } else { - data.apps.push(item) - } - } - + const data = parseBackupForm(selected.value, system) api .put({ uri: `backups/${props.name}/restore`, - data, + // FIXME force? + data: { ...data, force: '' }, humanKey: { key: 'backups.restore', name: props.name }, }) .then(() => { @@ -105,7 +69,7 @@ async function restoreBackup() { }) .catch((err: APIError) => { if (!(err instanceof APIBadRequestError)) throw err - error.value = err.message + serverError.value = err.message isValid.value = false }) } @@ -136,7 +100,7 @@ function downloadBackup() { - - - +