feat(server): added in update server as well as get serverdata

This commit is contained in:
2025-03-15 15:32:15 -05:00
parent 359427824b
commit df252e72b3
8 changed files with 315 additions and 46 deletions

View File

@@ -5,9 +5,43 @@ import {serverData} from "../../database/schema/serverData.js";
import {eq, sql} from "drizzle-orm";
import {createLog} from "../services/logger/logger.js";
const updateServer = async (devApp: string, server: string) => {
type UpdateServerResponse = {
success: boolean;
message: string;
};
export const updateServer = async (devApp: string, server: string | null): Promise<UpdateServerResponse> => {
const app = await getAppInfo(devApp);
const serverInfo = await db.select().from(serverData).where(eq(serverData.sName, server.toLowerCase()));
const serverInfo = await db
.select()
.from(serverData)
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
if (serverInfo.length === 0) {
createLog(
"error",
"lst",
"serverUpdater",
`Looks like you are missing the plant token or have entered an incorrect one please try again.`
);
return {
success: false,
message: "Looks like you are missing the plant token or have entered an incorrect one please try again.",
};
}
if (serverInfo[0].isUpgrading) {
createLog(
"error",
"lst",
"serverUpdater",
`Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`
);
return {
success: false,
message: `Looks like ${serverInfo[0].plantToken} is upgrading already you cant do this again.`,
};
}
const scriptPath = `${process.env.DEVFOLDER}\\server\\scripts\\update.ps1 `;
const args = [
@@ -39,9 +73,13 @@ const updateServer = async (devApp: string, server: string) => {
,
];
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
const process = spawn("powershell", args);
// change the server to upgradeing
await db
.update(serverData)
.set({isUpgrading: true})
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
//let stdout = "";
//let stderr = "";
@@ -69,7 +107,16 @@ const updateServer = async (devApp: string, server: string) => {
//update the last build.
try {
await db.update(serverData).set({lastUpdated: sql`NOW()`});
await db
.update(serverData)
.set({lastUpdated: sql`NOW()`, isUpgrading: false})
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
createLog(
"info",
"lst",
"serverUpdater",
`${server?.toLowerCase()}, has been updated and can now be used again.`
);
} catch (error) {
createLog(
"error",
@@ -79,7 +126,10 @@ const updateServer = async (devApp: string, server: string) => {
);
}
resolve({success: true, code});
resolve({
success: true,
message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
});
} else {
const errorMessage = `Process exited with code ${code}`;
@@ -87,7 +137,10 @@ const updateServer = async (devApp: string, server: string) => {
// //onClose(code);
// }
reject(new Error(errorMessage));
reject({
success: false,
message: `${server?.toLowerCase()}, Has encounted an error while updating.`,
});
}
});
@@ -107,7 +160,7 @@ export async function processAllServers(devApp: string) {
let count = 1;
for (const server of servers) {
try {
const updateToServer = await updateServer(devApp, server.sName);
const updateToServer = await updateServer(devApp, server.plantToken);
createLog("info", "lst", "serverUpdater", `${server.sName} was updated.`);
count = count + 1;
@@ -118,5 +171,3 @@ export async function processAllServers(devApp: string) {
}
}
}
updateServer("C:\\Users\\matthes01\\Documents\\lstv2", "test");

View File

@@ -9,6 +9,7 @@ import {getAppInfo} from "../globalUtils/appInfo.js";
const ignoreList = [
".git",
"builds",
"server",
"node_modules",
"apiDocsLSTV2",
"testFiles",
@@ -19,7 +20,7 @@ const ignoreList = [
"nssm.exe",
"postgresql-17.2-3-windows-x64.exe",
// front end ignore
"/frontend/node_modules",
"frontend/node_modules",
"fonrtend/.env",
"frontend/public",
"frontend/src",
@@ -33,6 +34,7 @@ const ignoreList = [
"frontend/tsconfig.app.json",
"frontend/tsconfig.node.json",
"frontend/vite.config.ts",
"frontend/components.json",
];
const shouldIgnore = (itemPath: any) => {
@@ -40,7 +42,10 @@ const shouldIgnore = (itemPath: any) => {
return ignoreList.some((ignorePattern) => {
const normalizedIgnorePatther = ignorePattern.replace(/\\/g, "/");
return normalizedItemPath.includes(normalizedIgnorePatther);
return (
normalizedItemPath === normalizedIgnorePatther ||
normalizedItemPath.startsWith(`${normalizedIgnorePatther}/`)
);
});
};