From d509ffc9db1ed720c450a3596e46fc05c61ebcd6 Mon Sep 17 00:00:00 2001 From: oxdev03 <140103378+oxdev03@users.noreply.github.com> Date: Sat, 7 Sep 2024 10:48:00 +0200 Subject: [PATCH] fix: invalid process type, fixes #40 --- apps/backend/utils/processInfo.ts | 7 ++++++- packages/typings/src/process.ts | 31 +++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/apps/backend/utils/processInfo.ts b/apps/backend/utils/processInfo.ts index 6930adc..911b8d4 100644 --- a/apps/backend/utils/processInfo.ts +++ b/apps/backend/utils/processInfo.ts @@ -1,3 +1,4 @@ +import { IProcessType, PROCESS_TYPES } from "@pm2.web/typings"; import bytes from "bytes-iec"; import pm2 from "pm2"; @@ -26,6 +27,8 @@ const getProcessInfo = async (): Promise => { unit: "", }; + const interpreter = item?.pm2_env?.exec_interpreter; + return { name: item.name || item.pm_id, pm_id: item.pm_id, @@ -44,7 +47,9 @@ const getProcessInfo = async (): Promise => { unstaged: item.pm2_env?.versioning?.unstaged ?? true, }, status: item?.pm2_env?.status || "offline", - type: item?.pm2_env?.exec_interpreter || "", + type: PROCESS_TYPES.includes(interpreter as IProcessType) + ? interpreter + : "other", }; }) .filter((item) => !!item) as IProcessInfo[]; diff --git a/packages/typings/src/process.ts b/packages/typings/src/process.ts index bf11d39..6518b00 100644 --- a/packages/typings/src/process.ts +++ b/packages/typings/src/process.ts @@ -7,17 +7,20 @@ interface ILog { _id: string; } -type IProcessType = - | "node" - | "python" - | "ruby" - | "php" - | "bash" - | "go" - | "dotnet" - | "shell" - | "java" - | "other"; +const PROCESS_TYPES = [ + "node", + "python", + "ruby", + "php", + "bash", + "go", + "dotnet", + "shell", + "java", + "other", +] + +type IProcessType = typeof PROCESS_TYPES[number]; type IProcessStatus = | "online" @@ -58,5 +61,9 @@ export type { IProcessType, IProcessStatus, IProcess, - IProcessModel, + IProcessModel }; + +export { + PROCESS_TYPES +}