feat(server): added in update server as well as get serverdata
This commit is contained in:
@@ -22,6 +22,7 @@ import { Route as OcpLotsImport } from './routes/ocp/lots'
|
|||||||
import { Route as EomEomImport } from './routes/_eom/eom'
|
import { Route as EomEomImport } from './routes/_eom/eom'
|
||||||
import { Route as AuthProfileImport } from './routes/_auth/profile'
|
import { Route as AuthProfileImport } from './routes/_auth/profile'
|
||||||
import { Route as AdminSettingsImport } from './routes/_admin/settings'
|
import { Route as AdminSettingsImport } from './routes/_admin/settings'
|
||||||
|
import { Route as AdminServersImport } from './routes/_admin/servers'
|
||||||
import { Route as AdminModulesImport } from './routes/_admin/modules'
|
import { Route as AdminModulesImport } from './routes/_admin/modules'
|
||||||
import { Route as logisticsMaterialHelperIndexImport } from './routes/(logistics)/materialHelper/index'
|
import { Route as logisticsMaterialHelperIndexImport } from './routes/(logistics)/materialHelper/index'
|
||||||
import { Route as EomArticleAvImport } from './routes/_eom/article/$av'
|
import { Route as EomArticleAvImport } from './routes/_eom/article/$av'
|
||||||
@@ -93,6 +94,12 @@ const AdminSettingsRoute = AdminSettingsImport.update({
|
|||||||
getParentRoute: () => AdminRoute,
|
getParentRoute: () => AdminRoute,
|
||||||
} as any)
|
} as any)
|
||||||
|
|
||||||
|
const AdminServersRoute = AdminServersImport.update({
|
||||||
|
id: '/servers',
|
||||||
|
path: '/servers',
|
||||||
|
getParentRoute: () => AdminRoute,
|
||||||
|
} as any)
|
||||||
|
|
||||||
const AdminModulesRoute = AdminModulesImport.update({
|
const AdminModulesRoute = AdminModulesImport.update({
|
||||||
id: '/modules',
|
id: '/modules',
|
||||||
path: '/modules',
|
path: '/modules',
|
||||||
@@ -179,6 +186,13 @@ declare module '@tanstack/react-router' {
|
|||||||
preLoaderRoute: typeof AdminModulesImport
|
preLoaderRoute: typeof AdminModulesImport
|
||||||
parentRoute: typeof AdminImport
|
parentRoute: typeof AdminImport
|
||||||
}
|
}
|
||||||
|
'/_admin/servers': {
|
||||||
|
id: '/_admin/servers'
|
||||||
|
path: '/servers'
|
||||||
|
fullPath: '/servers'
|
||||||
|
preLoaderRoute: typeof AdminServersImport
|
||||||
|
parentRoute: typeof AdminImport
|
||||||
|
}
|
||||||
'/_admin/settings': {
|
'/_admin/settings': {
|
||||||
id: '/_admin/settings'
|
id: '/_admin/settings'
|
||||||
path: '/settings'
|
path: '/settings'
|
||||||
@@ -249,11 +263,13 @@ declare module '@tanstack/react-router' {
|
|||||||
|
|
||||||
interface AdminRouteChildren {
|
interface AdminRouteChildren {
|
||||||
AdminModulesRoute: typeof AdminModulesRoute
|
AdminModulesRoute: typeof AdminModulesRoute
|
||||||
|
AdminServersRoute: typeof AdminServersRoute
|
||||||
AdminSettingsRoute: typeof AdminSettingsRoute
|
AdminSettingsRoute: typeof AdminSettingsRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
const AdminRouteChildren: AdminRouteChildren = {
|
const AdminRouteChildren: AdminRouteChildren = {
|
||||||
AdminModulesRoute: AdminModulesRoute,
|
AdminModulesRoute: AdminModulesRoute,
|
||||||
|
AdminServersRoute: AdminServersRoute,
|
||||||
AdminSettingsRoute: AdminSettingsRoute,
|
AdminSettingsRoute: AdminSettingsRoute,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,6 +303,7 @@ export interface FileRoutesByFullPath {
|
|||||||
'/about': typeof AboutRoute
|
'/about': typeof AboutRoute
|
||||||
'/login': typeof LoginRoute
|
'/login': typeof LoginRoute
|
||||||
'/modules': typeof AdminModulesRoute
|
'/modules': typeof AdminModulesRoute
|
||||||
|
'/servers': typeof AdminServersRoute
|
||||||
'/settings': typeof AdminSettingsRoute
|
'/settings': typeof AdminSettingsRoute
|
||||||
'/profile': typeof AuthProfileRoute
|
'/profile': typeof AuthProfileRoute
|
||||||
'/eom': typeof EomEomRoute
|
'/eom': typeof EomEomRoute
|
||||||
@@ -304,6 +321,7 @@ export interface FileRoutesByTo {
|
|||||||
'/about': typeof AboutRoute
|
'/about': typeof AboutRoute
|
||||||
'/login': typeof LoginRoute
|
'/login': typeof LoginRoute
|
||||||
'/modules': typeof AdminModulesRoute
|
'/modules': typeof AdminModulesRoute
|
||||||
|
'/servers': typeof AdminServersRoute
|
||||||
'/settings': typeof AdminSettingsRoute
|
'/settings': typeof AdminSettingsRoute
|
||||||
'/profile': typeof AuthProfileRoute
|
'/profile': typeof AuthProfileRoute
|
||||||
'/eom': typeof EomEomRoute
|
'/eom': typeof EomEomRoute
|
||||||
@@ -324,6 +342,7 @@ export interface FileRoutesById {
|
|||||||
'/about': typeof AboutRoute
|
'/about': typeof AboutRoute
|
||||||
'/login': typeof LoginRoute
|
'/login': typeof LoginRoute
|
||||||
'/_admin/modules': typeof AdminModulesRoute
|
'/_admin/modules': typeof AdminModulesRoute
|
||||||
|
'/_admin/servers': typeof AdminServersRoute
|
||||||
'/_admin/settings': typeof AdminSettingsRoute
|
'/_admin/settings': typeof AdminSettingsRoute
|
||||||
'/_auth/profile': typeof AuthProfileRoute
|
'/_auth/profile': typeof AuthProfileRoute
|
||||||
'/_eom/eom': typeof EomEomRoute
|
'/_eom/eom': typeof EomEomRoute
|
||||||
@@ -343,6 +362,7 @@ export interface FileRouteTypes {
|
|||||||
| '/about'
|
| '/about'
|
||||||
| '/login'
|
| '/login'
|
||||||
| '/modules'
|
| '/modules'
|
||||||
|
| '/servers'
|
||||||
| '/settings'
|
| '/settings'
|
||||||
| '/profile'
|
| '/profile'
|
||||||
| '/eom'
|
| '/eom'
|
||||||
@@ -359,6 +379,7 @@ export interface FileRouteTypes {
|
|||||||
| '/about'
|
| '/about'
|
||||||
| '/login'
|
| '/login'
|
||||||
| '/modules'
|
| '/modules'
|
||||||
|
| '/servers'
|
||||||
| '/settings'
|
| '/settings'
|
||||||
| '/profile'
|
| '/profile'
|
||||||
| '/eom'
|
| '/eom'
|
||||||
@@ -377,6 +398,7 @@ export interface FileRouteTypes {
|
|||||||
| '/about'
|
| '/about'
|
||||||
| '/login'
|
| '/login'
|
||||||
| '/_admin/modules'
|
| '/_admin/modules'
|
||||||
|
| '/_admin/servers'
|
||||||
| '/_admin/settings'
|
| '/_admin/settings'
|
||||||
| '/_auth/profile'
|
| '/_auth/profile'
|
||||||
| '/_eom/eom'
|
| '/_eom/eom'
|
||||||
@@ -449,6 +471,7 @@ export const routeTree = rootRoute
|
|||||||
"filePath": "_admin.tsx",
|
"filePath": "_admin.tsx",
|
||||||
"children": [
|
"children": [
|
||||||
"/_admin/modules",
|
"/_admin/modules",
|
||||||
|
"/_admin/servers",
|
||||||
"/_admin/settings"
|
"/_admin/settings"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -475,6 +498,10 @@ export const routeTree = rootRoute
|
|||||||
"filePath": "_admin/modules.tsx",
|
"filePath": "_admin/modules.tsx",
|
||||||
"parent": "/_admin"
|
"parent": "/_admin"
|
||||||
},
|
},
|
||||||
|
"/_admin/servers": {
|
||||||
|
"filePath": "_admin/servers.tsx",
|
||||||
|
"parent": "/_admin"
|
||||||
|
},
|
||||||
"/_admin/settings": {
|
"/_admin/settings": {
|
||||||
"filePath": "_admin/settings.tsx",
|
"filePath": "_admin/settings.tsx",
|
||||||
"parent": "/_admin"
|
"parent": "/_admin"
|
||||||
|
|||||||
14
frontend/src/routes/_admin/servers.tsx
Normal file
14
frontend/src/routes/_admin/servers.tsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import ServerPage from "@/components/admin/servers/ServerPage";
|
||||||
|
import {createFileRoute} from "@tanstack/react-router";
|
||||||
|
|
||||||
|
export const Route = createFileRoute("/_admin/servers")({
|
||||||
|
component: RouteComponent,
|
||||||
|
});
|
||||||
|
|
||||||
|
function RouteComponent() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<ServerPage />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
19
frontend/src/utils/querys/servers.tsx
Normal file
19
frontend/src/utils/querys/servers.tsx
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import {queryOptions} from "@tanstack/react-query";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
export function getServers(token: string) {
|
||||||
|
return queryOptions({
|
||||||
|
queryKey: ["servers"],
|
||||||
|
queryFn: () => fetchSettings(token),
|
||||||
|
enabled: !!token,
|
||||||
|
staleTime: 1000,
|
||||||
|
refetchInterval: 500,
|
||||||
|
refetchOnWindowFocus: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetchSettings = async (token: string) => {
|
||||||
|
const {data} = await axios.get("/api/server/servers", {headers: {Authorization: `Bearer ${token}`}});
|
||||||
|
|
||||||
|
return data.data;
|
||||||
|
};
|
||||||
@@ -5,9 +5,43 @@ import {serverData} from "../../database/schema/serverData.js";
|
|||||||
import {eq, sql} from "drizzle-orm";
|
import {eq, sql} from "drizzle-orm";
|
||||||
import {createLog} from "../services/logger/logger.js";
|
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 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 scriptPath = `${process.env.DEVFOLDER}\\server\\scripts\\update.ps1 `;
|
||||||
const args = [
|
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);
|
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 stdout = "";
|
||||||
//let stderr = "";
|
//let stderr = "";
|
||||||
|
|
||||||
@@ -69,7 +107,16 @@ const updateServer = async (devApp: string, server: string) => {
|
|||||||
|
|
||||||
//update the last build.
|
//update the last build.
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
createLog(
|
createLog(
|
||||||
"error",
|
"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 {
|
} else {
|
||||||
const errorMessage = `Process exited with code ${code}`;
|
const errorMessage = `Process exited with code ${code}`;
|
||||||
|
|
||||||
@@ -87,7 +137,10 @@ const updateServer = async (devApp: string, server: string) => {
|
|||||||
// //onClose(code);
|
// //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;
|
let count = 1;
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
try {
|
try {
|
||||||
const updateToServer = await updateServer(devApp, server.sName);
|
const updateToServer = await updateServer(devApp, server.plantToken);
|
||||||
createLog("info", "lst", "serverUpdater", `${server.sName} was updated.`);
|
createLog("info", "lst", "serverUpdater", `${server.sName} was updated.`);
|
||||||
count = count + 1;
|
count = count + 1;
|
||||||
|
|
||||||
@@ -118,5 +171,3 @@ export async function processAllServers(devApp: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateServer("C:\\Users\\matthes01\\Documents\\lstv2", "test");
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {getAppInfo} from "../globalUtils/appInfo.js";
|
|||||||
const ignoreList = [
|
const ignoreList = [
|
||||||
".git",
|
".git",
|
||||||
"builds",
|
"builds",
|
||||||
|
"server",
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"apiDocsLSTV2",
|
"apiDocsLSTV2",
|
||||||
"testFiles",
|
"testFiles",
|
||||||
@@ -19,7 +20,7 @@ const ignoreList = [
|
|||||||
"nssm.exe",
|
"nssm.exe",
|
||||||
"postgresql-17.2-3-windows-x64.exe",
|
"postgresql-17.2-3-windows-x64.exe",
|
||||||
// front end ignore
|
// front end ignore
|
||||||
"/frontend/node_modules",
|
"frontend/node_modules",
|
||||||
"fonrtend/.env",
|
"fonrtend/.env",
|
||||||
"frontend/public",
|
"frontend/public",
|
||||||
"frontend/src",
|
"frontend/src",
|
||||||
@@ -33,6 +34,7 @@ const ignoreList = [
|
|||||||
"frontend/tsconfig.app.json",
|
"frontend/tsconfig.app.json",
|
||||||
"frontend/tsconfig.node.json",
|
"frontend/tsconfig.node.json",
|
||||||
"frontend/vite.config.ts",
|
"frontend/vite.config.ts",
|
||||||
|
"frontend/components.json",
|
||||||
];
|
];
|
||||||
|
|
||||||
const shouldIgnore = (itemPath: any) => {
|
const shouldIgnore = (itemPath: any) => {
|
||||||
@@ -40,7 +42,10 @@ const shouldIgnore = (itemPath: any) => {
|
|||||||
|
|
||||||
return ignoreList.some((ignorePattern) => {
|
return ignoreList.some((ignorePattern) => {
|
||||||
const normalizedIgnorePatther = ignorePattern.replace(/\\/g, "/");
|
const normalizedIgnorePatther = ignorePattern.replace(/\\/g, "/");
|
||||||
return normalizedItemPath.includes(normalizedIgnorePatther);
|
return (
|
||||||
|
normalizedItemPath === normalizedIgnorePatther ||
|
||||||
|
normalizedItemPath.startsWith(`${normalizedIgnorePatther}/`)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
64
server/services/server/route/servers/getServers.ts
Normal file
64
server/services/server/route/servers/getServers.ts
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||||
|
import {db} from "../../../../../database/dbclient.js";
|
||||||
|
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
|
||||||
|
import {serverData} from "../../../../../database/schema/serverData.js";
|
||||||
|
import {eq} from "drizzle-orm";
|
||||||
|
|
||||||
|
// Define the request body schema
|
||||||
|
const requestSchema = z.object({
|
||||||
|
ip: z.string().optional(),
|
||||||
|
endpoint: z.string().optional(),
|
||||||
|
action: z.string().optional(),
|
||||||
|
stats: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Define the response schema
|
||||||
|
const responseSchema = z.object({
|
||||||
|
message: z.string().optional(),
|
||||||
|
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
|
||||||
|
name: z.string().openapi({example: "Production"}).optional(),
|
||||||
|
active: z.boolean().openapi({example: true}).optional(),
|
||||||
|
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["server"],
|
||||||
|
summary: "Returns all serverData on the server",
|
||||||
|
method: "get",
|
||||||
|
path: "/servers",
|
||||||
|
middleware: authMiddleware,
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
content: {
|
||||||
|
"application/json": {schema: responseSchema},
|
||||||
|
},
|
||||||
|
description: "Response message",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
//console.log("system modules");
|
||||||
|
let servers: any = [];
|
||||||
|
try {
|
||||||
|
servers = await db.select().from(serverData).where(eq(serverData.active, true));
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
servers = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort the servers by there name
|
||||||
|
servers = servers.sort((a: any, b: any) => a.sName.localeCompare(b.sName));
|
||||||
|
|
||||||
|
// Return response with the received data
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
message: `All active modules`,
|
||||||
|
data: servers,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default app;
|
||||||
93
server/services/server/route/updates/updateServer.ts
Normal file
93
server/services/server/route/updates/updateServer.ts
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import {z, createRoute, OpenAPIHono} from "@hono/zod-openapi";
|
||||||
|
import {authMiddleware} from "../../../auth/middleware/authMiddleware.js";
|
||||||
|
import {updateServer} from "../../../../scripts/updateServers.js";
|
||||||
|
|
||||||
|
// Define the request body schema
|
||||||
|
const requestSchema = z.object({
|
||||||
|
ip: z.string().optional(),
|
||||||
|
endpoint: z.string().optional(),
|
||||||
|
action: z.string().optional(),
|
||||||
|
stats: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Define the response schema
|
||||||
|
const responseSchema = z.object({
|
||||||
|
message: z.string().optional(),
|
||||||
|
module_id: z.string().openapi({example: "6c922c6c-7de3-4ec4-acb0-f068abdc"}).optional(),
|
||||||
|
name: z.string().openapi({example: "Production"}).optional(),
|
||||||
|
active: z.boolean().openapi({example: true}).optional(),
|
||||||
|
roles: z.string().openapi({example: `["viewer","technician"]`}).optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const ParamsSchema = z.object({
|
||||||
|
server: z
|
||||||
|
.string()
|
||||||
|
.min(3)
|
||||||
|
.openapi({
|
||||||
|
param: {
|
||||||
|
name: "server",
|
||||||
|
in: "path",
|
||||||
|
},
|
||||||
|
example: "usbow1",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const UpdateServer = z.object({
|
||||||
|
devDir: z.string().openapi({example: "C:\\something\\Something"}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["server"],
|
||||||
|
summary: "Updates server(s)",
|
||||||
|
method: "post",
|
||||||
|
path: "/update/:server",
|
||||||
|
middleware: authMiddleware,
|
||||||
|
request: {
|
||||||
|
params: ParamsSchema,
|
||||||
|
body: {
|
||||||
|
content: {
|
||||||
|
"application/json": {schema: UpdateServer},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
content: {
|
||||||
|
"application/json": {schema: responseSchema},
|
||||||
|
},
|
||||||
|
description: "Response message",
|
||||||
|
},
|
||||||
|
400: {
|
||||||
|
content: {
|
||||||
|
"application/json": {schema: responseSchema},
|
||||||
|
},
|
||||||
|
description: "Response message",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
const {server} = c.req.valid("param");
|
||||||
|
const body = await c.req.json();
|
||||||
|
|
||||||
|
// fire off the update we wont make this way
|
||||||
|
try {
|
||||||
|
const update = await updateServer(body.devDir, server);
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
success: update?.success ?? false,
|
||||||
|
message: update?.message,
|
||||||
|
data: [],
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: `${server} Encountered an ${error}`,
|
||||||
|
data: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
export default app;
|
||||||
@@ -14,44 +14,40 @@ export const serversCheckPoint = async () => {
|
|||||||
} else {
|
} else {
|
||||||
filePath = "./dist/server/services/server/utils/serverData.json";
|
filePath = "./dist/server/services/server/utils/serverData.json";
|
||||||
}
|
}
|
||||||
fs.readFile(filePath, "utf8", (err, data) => {
|
|
||||||
if (err) {
|
try {
|
||||||
console.error("Error reading JSON file:", err);
|
const data = fs.readFileSync(filePath, "utf8");
|
||||||
return;
|
const serverData = JSON.parse(data);
|
||||||
}
|
servers = serverData.servers;
|
||||||
servers = JSON.parse(data);
|
} catch (err) {
|
||||||
});
|
console.error("Error reading JSON file:", err);
|
||||||
|
}
|
||||||
|
|
||||||
// get the roles
|
// get the roles
|
||||||
try {
|
|
||||||
const settingsCheck = await db.select().from(serverData);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < servers.length; i++) {
|
for (let i = 0; i < servers.length; i++) {
|
||||||
const newRole = await db
|
const serverUpdate = await db
|
||||||
.insert(serverData)
|
.insert(serverData)
|
||||||
.values(servers[i])
|
.values(servers[i])
|
||||||
.onConflictDoUpdate({
|
.onConflictDoUpdate({
|
||||||
target: serverData.plantToken,
|
target: serverData.plantToken,
|
||||||
set: {
|
set: {
|
||||||
sName: servers[i].sName,
|
sName: servers[i].sName,
|
||||||
serverDNS: servers[i].serverDNS,
|
serverDNS: servers[i].serverDNS,
|
||||||
active: servers[i].active,
|
active: servers[i].active,
|
||||||
contactEmail: servers[i].contactEmail,
|
contactEmail: servers[i].contactEmail,
|
||||||
contactPhone: servers[i].contactPhone,
|
contactPhone: servers[i].contactPhone,
|
||||||
shippingHours: servers[i].shippingHours,
|
shippingHours: servers[i].shippingHours,
|
||||||
customerTiAcc: servers[i].customerTiAcc,
|
customerTiAcc: servers[i].customerTiAcc,
|
||||||
tiPostTime: servers[i].tiPostTime,
|
tiPostTime: servers[i].tiPostTime,
|
||||||
otherSettings: servers[i].otherSettings,
|
otherSettings: servers[i].otherSettings,
|
||||||
},
|
},
|
||||||
}) // this will only update the ones that are new :D
|
}) // this will only update the ones that are new :D
|
||||||
.returning({name: serverData.sName});
|
.returning({name: serverData.sName});
|
||||||
}
|
|
||||||
createLog("info", "lst", "server", "Servers were just added/updated due to server startup");
|
|
||||||
} catch (error) {
|
|
||||||
createLog("error", "lst", "server", `There was an error adding/updating serverData to the db, ${error}`);
|
|
||||||
}
|
}
|
||||||
|
createLog("info", "lst", "server", "Servers were just added/updated due to server startup");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createLog("error", "lst", "server", `There was an error adding serverData to the db, ${error}`);
|
createLog("error", "lst", "server", `There was an error adding/updating serverData to the db, ${error}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user