From 35cfcb1bcfc61c71eacbf483b0c365067d35ff34 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 13 Mar 2026 10:18:10 +0100 Subject: [PATCH] fix : merge develop --- server/api/disk.get.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/server/api/disk.get.ts b/server/api/disk.get.ts index 83ed9d9..ff16fb6 100644 --- a/server/api/disk.get.ts +++ b/server/api/disk.get.ts @@ -1,4 +1,4 @@ -import { execFile } from "child_process" +import { exec, execFile } from "child_process" import diskSources from "../config/disk-commands.json" type DiskSource = { @@ -8,7 +8,7 @@ type DiskSource = { args?: string[] } -function getCommand(source: DiskSource) { +function getEnvCommand(source: DiskSource) { const envKey = `DISK_COMMAND_${source.key.toUpperCase()}` const legacyEnvKey = source.key === "remote" ? "DISK_REMOTE_COMMAND" : source.key === "local" ? "DISK_LOCAL_COMMAND" : "" @@ -28,17 +28,26 @@ function runCommand(command: string, args: string[] = []): Promise { }) } +function runShellCommand(command: string): Promise { + return new Promise((resolve, reject) => { + exec(command, (error, stdout, stderr) => { + if (error) { + reject(stderr || error.message) + return + } + resolve(stdout) + }) + }) +} + export default defineEventHandler(async () => { const results = await Promise.all( (diskSources as DiskSource[]).map(async (source) => { try { - const command = getCommand(source) - - if (!command) { - throw new Error(`Commande manquante pour ${source.key}`) - } - - const output = await runCommand(command) + const envCommand = getEnvCommand(source) + const output = envCommand + ? await runShellCommand(envCommand) + : await runCommand(source.command, source.args || []) return { key: source.key, label: source.label,