fix : securite regex et message erreur et endpoint
This commit is contained in:
@@ -79,6 +79,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue"
|
||||
import { Icon as IconifyIcon } from "@iconify/vue"
|
||||
import { useApiAuthHeader } from "~/composables/useApiAuth"
|
||||
|
||||
type BackupScript = {
|
||||
key: string
|
||||
@@ -118,6 +119,7 @@ const scripts = ref<BackupScript[]>([])
|
||||
const output = ref<string>("")
|
||||
const message = ref<string>("")
|
||||
const isError = ref(false)
|
||||
const apiAuthHeader = useApiAuthHeader()
|
||||
|
||||
const statusClass = computed(() => (isError.value ? "status-error" : "status-success"))
|
||||
|
||||
@@ -134,12 +136,14 @@ const loadScripts = async () => {
|
||||
downloadFolders: []
|
||||
})
|
||||
try {
|
||||
const data = await $fetch<BackupScriptListResponse>("/api/backup-script")
|
||||
const data = await $fetch<BackupScriptListResponse>("/api/backup-script", {
|
||||
headers: apiAuthHeader
|
||||
})
|
||||
scripts.value = data.scripts
|
||||
} catch (error) {
|
||||
} catch {
|
||||
scripts.value = []
|
||||
isError.value = true
|
||||
message.value = `Erreur chargement scripts: ${error instanceof Error ? error.message : String(error)}`
|
||||
message.value = "Erreur lors de l'opération"
|
||||
emit("result", {
|
||||
key: null,
|
||||
label: "",
|
||||
@@ -162,7 +166,8 @@ const runScript = async (key: string) => {
|
||||
try {
|
||||
const data = await $fetch<BackupScriptRunResponse>("/api/backup-script", {
|
||||
method: "POST",
|
||||
body: { key }
|
||||
body: { key },
|
||||
headers: apiAuthHeader
|
||||
})
|
||||
message.value = `${data.label} execute avec succes`
|
||||
output.value = data.output || "Aucune sortie retournee."
|
||||
@@ -173,8 +178,20 @@ const runScript = async (key: string) => {
|
||||
isError: false,
|
||||
downloadFolders: data.downloadFolders || []
|
||||
})
|
||||
} catch (error: any) {
|
||||
} catch (error: unknown) {
|
||||
isError.value = true
|
||||
const statusMessage =
|
||||
typeof error === "object" &&
|
||||
error !== null &&
|
||||
"data" in error &&
|
||||
typeof error.data === "object" &&
|
||||
error.data !== null &&
|
||||
"statusMessage" in error.data &&
|
||||
typeof error.data.statusMessage === "string"
|
||||
? error.data.statusMessage
|
||||
: null
|
||||
|
||||
message.value = statusMessage || "Erreur lors de l'opération"
|
||||
message.value = error?.data?.statusMessage || "Erreur execution script"
|
||||
output.value = ""
|
||||
emit("result", {
|
||||
|
||||
Reference in New Issue
Block a user