fix: use env only

This commit is contained in:
2026-03-16 14:43:55 +01:00
parent 69c192c35a
commit e13e1eb3dd
6 changed files with 69 additions and 95 deletions

View File

@@ -1,17 +1,9 @@
import { execFile } from "node:child_process"
import scripts from "../config/backup-script.json"
import { exec } from "node:child_process"
import { backupScripts, getBackupScriptCommand } from "../utils/backup-scripts"
type BackupScript = {
key: string
label: string
downloadFolders?: string[]
command: string
args?: string[]
}
function runCommand(command: string, args: string[] = []): Promise<string> {
function runCommand(command: string): Promise<string> {
return new Promise((resolve, reject) => {
execFile(command, args, { timeout: 10 * 60 * 1000 }, (error, stdout, stderr) => {
exec(command, { timeout: 10 * 60 * 1000 }, (error, stdout, stderr) => {
if (error) {
reject(stderr || error.message)
return
@@ -32,7 +24,7 @@ export default defineEventHandler(async (event) => {
})
}
const script = (scripts as BackupScript[]).find((item) => item.key === key)
const script = backupScripts.find((item) => item.key === key)
if (!script) {
throw createError({
statusCode: 404,
@@ -41,7 +33,15 @@ export default defineEventHandler(async (event) => {
}
try {
const output = await runCommand(script.command, script.args || [])
const command = getBackupScriptCommand(script.key)
if (!command) {
throw createError({
statusCode: 500,
statusMessage: "Commande de script manquante"
})
}
const output = await runCommand(command)
return {
ok: true,
key: script.key,