feat : new ui et message discord
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
import { exec } from "child_process"
|
||||
import diskSources from "../config/disk-commands.json"
|
||||
|
||||
const remoteCommand =
|
||||
process.env.DISK_REMOTE_COMMAND ||
|
||||
"ssh malio-b@192.168.0.179 'cd /home/malio-b/Scripts-Serveur && bash check_storage.sh && exit'"
|
||||
type DiskSource = {
|
||||
key: string
|
||||
label: string
|
||||
command: string
|
||||
}
|
||||
|
||||
const localCommand =
|
||||
process.env.DISK_LOCAL_COMMAND ||
|
||||
"bash /home/kevin/check_storage.sh"
|
||||
function getCommand(source: DiskSource) {
|
||||
const envKey = `DISK_COMMAND_${source.key.toUpperCase()}`
|
||||
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
|
||||
}
|
||||
|
||||
function runCommand(command: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -21,25 +28,26 @@ function runCommand(command: string): Promise<string> {
|
||||
}
|
||||
|
||||
export default defineEventHandler(async () => {
|
||||
const [remoteResult, localResult] = await Promise.allSettled([
|
||||
runCommand(remoteCommand),
|
||||
runCommand(localCommand)
|
||||
])
|
||||
const results = await Promise.all(
|
||||
(diskSources as DiskSource[]).map(async (source) => {
|
||||
try {
|
||||
const output = await runCommand(getCommand(source))
|
||||
return {
|
||||
key: source.key,
|
||||
label: source.label,
|
||||
ok: true,
|
||||
output
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
key: source.key,
|
||||
label: source.label,
|
||||
ok: false,
|
||||
output: `Erreur: ${String(error)}`
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return {
|
||||
remote: {
|
||||
ok: remoteResult.status === "fulfilled",
|
||||
output:
|
||||
remoteResult.status === "fulfilled"
|
||||
? remoteResult.value
|
||||
: `Erreur: ${String(remoteResult.reason)}`
|
||||
},
|
||||
local: {
|
||||
ok: localResult.status === "fulfilled",
|
||||
output:
|
||||
localResult.status === "fulfilled"
|
||||
? localResult.value
|
||||
: `Erreur: ${String(localResult.reason)}`
|
||||
}
|
||||
}
|
||||
return { results }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user