From 76436001969dbdf327943868e860d3fc25b0597b Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 12 Mar 2026 09:42:28 +0100 Subject: [PATCH] fix : env --- .env.example | 5 +++++ server/api/backups.get.ts | 6 +++--- server/api/disk.get.ts | 10 ++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index a804ab9..19f1dd2 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,8 @@ API_SECRET_KEY= DISCORD_BOT_TOKEN= DISCORD_CHANNEL_ID= +BACKUPS_REMOTE_HOST= +BACKUPS_REMOTE_ROOT= +BACKUPS_MAX_FILES= +DISK_COMMAND_REMOTE= +DISK_COMMAND_LOCAL= \ No newline at end of file diff --git a/server/api/backups.get.ts b/server/api/backups.get.ts index f81ecb9..0c968bd 100644 --- a/server/api/backups.get.ts +++ b/server/api/backups.get.ts @@ -1,9 +1,9 @@ import { execFile } from "node:child_process" import folderMap from "../config/backup-folders.json" -const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST || "malio-b" -const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT || "/home/malio-b/backups" -const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES || "200") +const REMOTE_HOST = process.env.BACKUPS_REMOTE_HOST +const REMOTE_ROOT = process.env.BACKUPS_REMOTE_ROOT +const MAX_FILES_PER_FOLDER = Number(process.env.BACKUPS_MAX_FILES) const isSafeFolder = (value: string) => /^[a-zA-Z0-9._-]+$/.test(value) const shellQuote = (value: string) => `'${value.replace(/'/g, `'\\''`)}'` const FOLDER_MAP = folderMap as Record diff --git a/server/api/disk.get.ts b/server/api/disk.get.ts index da537a9..cbf95ca 100644 --- a/server/api/disk.get.ts +++ b/server/api/disk.get.ts @@ -12,7 +12,7 @@ function getCommand(source: DiskSource) { const legacyEnvKey = source.key === "remote" ? "DISK_REMOTE_COMMAND" : source.key === "local" ? "DISK_LOCAL_COMMAND" : "" - return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || source.command + return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || null } function runCommand(command: string): Promise { @@ -31,7 +31,13 @@ export default defineEventHandler(async () => { const results = await Promise.all( (diskSources as DiskSource[]).map(async (source) => { try { - const output = await runCommand(getCommand(source)) + const command = getCommand(source) + + if (!command) { + throw new Error(`Commande manquante pour ${source.key}`) + } + + const output = await runCommand(command) return { key: source.key, label: source.label,