Compare commits
4 Commits
04eb2e3e14
...
b01980e1c5
| Author | SHA1 | Date | |
|---|---|---|---|
| b01980e1c5 | |||
| fe0c500dcf | |||
| 8a040d15db | |||
| f90066c090 |
17
database/migrations/0026_daily_the_twelve.sql
Normal file
17
database/migrations/0026_daily_the_twelve.sql
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
CREATE TABLE "printers" (
|
||||||
|
"printer_id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"humanReadableId" text,
|
||||||
|
"name" text NOT NULL,
|
||||||
|
"ipAddress" text,
|
||||||
|
"port" numeric NOT NULL,
|
||||||
|
"status" text,
|
||||||
|
"statusText" text NOT NULL,
|
||||||
|
"lastTimePrinted" text,
|
||||||
|
"assigned" boolean DEFAULT false NOT NULL,
|
||||||
|
"remark" text,
|
||||||
|
"monitorState" boolean DEFAULT false NOT NULL,
|
||||||
|
"add_Date" timestamp DEFAULT now(),
|
||||||
|
"upd_date" timestamp DEFAULT now()
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX "humanReadableId" ON "printers" USING btree ("name");
|
||||||
3
database/migrations/0027_needy_sleepwalker.sql
Normal file
3
database/migrations/0027_needy_sleepwalker.sql
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
ALTER TABLE "printers" ALTER COLUMN "statusText" DROP NOT NULL;--> statement-breakpoint
|
||||||
|
ALTER TABLE "printers" ALTER COLUMN "assigned" DROP NOT NULL;--> statement-breakpoint
|
||||||
|
ALTER TABLE "printers" ALTER COLUMN "monitorState" DROP NOT NULL;
|
||||||
1
database/migrations/0028_fast_wong.sql
Normal file
1
database/migrations/0028_fast_wong.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE "printers" ALTER COLUMN "port" DROP NOT NULL;
|
||||||
2
database/migrations/0029_giant_blue_blade.sql
Normal file
2
database/migrations/0029_giant_blue_blade.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
DROP INDEX "humanReadableId";--> statement-breakpoint
|
||||||
|
CREATE UNIQUE INDEX "humanReadableId" ON "printers" USING btree ("humanReadableId");
|
||||||
1168
database/migrations/meta/0026_snapshot.json
Normal file
1168
database/migrations/meta/0026_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1168
database/migrations/meta/0027_snapshot.json
Normal file
1168
database/migrations/meta/0027_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1168
database/migrations/meta/0028_snapshot.json
Normal file
1168
database/migrations/meta/0028_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1168
database/migrations/meta/0029_snapshot.json
Normal file
1168
database/migrations/meta/0029_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -183,6 +183,34 @@
|
|||||||
"when": 1742655504936,
|
"when": 1742655504936,
|
||||||
"tag": "0025_amusing_sugar_man",
|
"tag": "0025_amusing_sugar_man",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 26,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1742914066219,
|
||||||
|
"tag": "0026_daily_the_twelve",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 27,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1742917145140,
|
||||||
|
"tag": "0027_needy_sleepwalker",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 28,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1742917676211,
|
||||||
|
"tag": "0028_fast_wong",
|
||||||
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 29,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1742917978318,
|
||||||
|
"tag": "0029_giant_blue_blade",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
42
database/schema/printers.ts
Normal file
42
database/schema/printers.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import {
|
||||||
|
text,
|
||||||
|
pgTable,
|
||||||
|
numeric,
|
||||||
|
index,
|
||||||
|
timestamp,
|
||||||
|
boolean,
|
||||||
|
uuid,
|
||||||
|
uniqueIndex,
|
||||||
|
} from "drizzle-orm/pg-core";
|
||||||
|
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
export const printers = pgTable(
|
||||||
|
"printers",
|
||||||
|
{
|
||||||
|
printer_id: uuid("printer_id").defaultRandom().primaryKey(),
|
||||||
|
humanReadableId: text("humanReadableId"),
|
||||||
|
name: text("name").notNull(),
|
||||||
|
ipAddress: text("ipAddress"),
|
||||||
|
port: numeric("port"),
|
||||||
|
status: text("status"),
|
||||||
|
statusText: text("statusText"),
|
||||||
|
lastTimePrinted: text("lastTimePrinted"),
|
||||||
|
assigned: boolean("assigned").default(false),
|
||||||
|
remark: text("remark"),
|
||||||
|
monitorState: boolean("monitorState").default(false),
|
||||||
|
add_Date: timestamp("add_Date").defaultNow(),
|
||||||
|
upd_date: timestamp("upd_date").defaultNow(),
|
||||||
|
},
|
||||||
|
(table) => [
|
||||||
|
//uniqueIndex("emailUniqueIndex").on(sql`lower(${table.email})`),
|
||||||
|
uniqueIndex("humanReadableId").on(table.humanReadableId),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Schema for inserting a user - can be used to validate API requests
|
||||||
|
// export const insertRolesSchema = createInsertSchema(roles, {
|
||||||
|
// name: z.string().min(3, {message: "Role name must be more than 3 letters"}),
|
||||||
|
// });
|
||||||
|
// Schema for selecting a Expenses - can be used to validate API responses
|
||||||
|
export const selectRolesSchema = createSelectSchema(printers);
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||||
import { serve } from "@hono/node-server";
|
import { serve } from "@hono/node-server";
|
||||||
import { OpenAPIHono } from "@hono/zod-openapi";
|
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
import { proxy } from "hono/proxy";
|
|
||||||
import { serveStatic } from "@hono/node-server/serve-static";
|
import { serveStatic } from "@hono/node-server/serve-static";
|
||||||
import { logger } from "hono/logger";
|
import { logger } from "hono/logger";
|
||||||
import { cors } from "hono/cors";
|
import { cors } from "hono/cors";
|
||||||
import { createLog } from "./services/logger/logger.js";
|
import { createLog } from "./services/logger/logger.js";
|
||||||
import { WebSocketServer } from "ws";
|
|
||||||
// custom routes
|
// custom routes
|
||||||
import scalar from "./services/general/route/scalar.js";
|
import scalar from "./services/general/route/scalar.js";
|
||||||
import system from "./services/server/systemServer.js";
|
import system from "./services/server/systemServer.js";
|
||||||
|
|||||||
@@ -4,317 +4,197 @@ import { db } from "../../database/dbclient.js";
|
|||||||
import { serverData } from "../../database/schema/serverData.js";
|
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";
|
||||||
import { spawn } from "child_process";
|
|
||||||
import { getAppInfo } from "../globalUtils/appInfo.js";
|
|
||||||
import { db } from "../../database/dbclient.js";
|
|
||||||
import { serverData } from "../../database/schema/serverData.js";
|
|
||||||
import { eq, sql } from "drizzle-orm";
|
|
||||||
import { createLog } from "../services/logger/logger.js";
|
|
||||||
|
|
||||||
type UpdateServerResponse = {
|
type UpdateServerResponse = {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
success: boolean;
|
|
||||||
message: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateServer = async (
|
export const updateServer = async (
|
||||||
devApp: string,
|
devApp: string,
|
||||||
server: string | null
|
server: string | null
|
||||||
): Promise<UpdateServerResponse> => {
|
): Promise<UpdateServerResponse> => {
|
||||||
const app = await getAppInfo(devApp);
|
const app = await getAppInfo(devApp);
|
||||||
const serverInfo = await db
|
const serverInfo = await db
|
||||||
export const updateServer = async (
|
.select()
|
||||||
devApp: string,
|
.from(serverData)
|
||||||
server: string | null
|
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
||||||
): Promise<UpdateServerResponse> => {
|
|
||||||
const app = await getAppInfo(devApp);
|
|
||||||
const serverInfo = await db
|
|
||||||
.select()
|
|
||||||
.from(serverData)
|
|
||||||
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
|
||||||
|
|
||||||
if (serverInfo.length === 0) {
|
if (serverInfo.length === 0) {
|
||||||
createLog(
|
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.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.`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
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 = [
|
|
||||||
"-NoProfile",
|
|
||||||
"-ExecutionPolicy",
|
|
||||||
"Bypass",
|
|
||||||
"-File",
|
|
||||||
scriptPath,
|
|
||||||
"-username",
|
|
||||||
process.env.ADMUSER, // needs moved to somewhere else.
|
|
||||||
"-admpass",
|
|
||||||
process.env.ADMPASSWORD, // needs moved to somewhere else.
|
|
||||||
"-devFolder",
|
|
||||||
process.env.DEVFOLDER,
|
|
||||||
"-server",
|
|
||||||
serverInfo[0].serverDNS,
|
|
||||||
"-serverIP",
|
|
||||||
serverInfo[0].idAddress,
|
|
||||||
"-token",
|
|
||||||
serverInfo[0].plantToken,
|
|
||||||
"-build",
|
|
||||||
`${process.env.DEVFOLDER}\\builds`,
|
|
||||||
"-location",
|
|
||||||
serverInfo[0].serverLoc,
|
|
||||||
"-obslst",
|
|
||||||
serverInfo[0].oldVersion,
|
|
||||||
"-obsBuild",
|
|
||||||
app.admConfig.oldBuild,
|
|
||||||
,
|
|
||||||
];
|
|
||||||
|
|
||||||
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 = "";
|
|
||||||
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 = "";
|
|
||||||
|
|
||||||
// Collect stdout data
|
|
||||||
process.stdout.on("data", (data) => {
|
|
||||||
const output = data.toString().trim();
|
|
||||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
|
||||||
//onData(output);
|
|
||||||
});
|
|
||||||
// Collect stdout data
|
|
||||||
process.stdout.on("data", (data) => {
|
|
||||||
const output = data.toString().trim();
|
|
||||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
|
||||||
//onData(output);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Collect stderr data
|
|
||||||
process.stderr.on("data", (data) => {
|
|
||||||
const output = data.toString().trim();
|
|
||||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
|
||||||
//onData(output);
|
|
||||||
});
|
|
||||||
// Collect stderr data
|
|
||||||
process.stderr.on("data", (data) => {
|
|
||||||
const output = data.toString().trim();
|
|
||||||
createLog("info", "lst", "serverUpdater", `${output}`);
|
|
||||||
//onData(output);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle process close
|
|
||||||
process.on("close", async (code) => {
|
|
||||||
if (code === 0) {
|
|
||||||
// if (count >= servers) {
|
|
||||||
// //onClose(`Server completed with code: ${code}`);
|
|
||||||
// }
|
|
||||||
createLog("info", "lst", "serverUpdater", `${server}`);
|
|
||||||
// Handle process close
|
|
||||||
process.on("close", async (code) => {
|
|
||||||
if (code === 0) {
|
|
||||||
// if (count >= servers) {
|
|
||||||
// //onClose(`Server completed with code: ${code}`);
|
|
||||||
// }
|
|
||||||
createLog("info", "lst", "serverUpdater", `${server}`);
|
|
||||||
|
|
||||||
//update the last build.
|
|
||||||
try {
|
|
||||||
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",
|
"error",
|
||||||
"lst",
|
"lst",
|
||||||
"serverUpdater",
|
"serverUpdater",
|
||||||
`There was an error updating the last time the server was updated: ${error}`
|
`Looks like you are missing the plant token or have entered an incorrect one please try again.`
|
||||||
);
|
);
|
||||||
}
|
return {
|
||||||
//update the last build.
|
success: false,
|
||||||
try {
|
message:
|
||||||
await db
|
"Looks like you are missing the plant token or have entered an incorrect one please try again.",
|
||||||
.update(serverData)
|
};
|
||||||
.set({ lastUpdated: sql`NOW()`, isUpgrading: false })
|
}
|
||||||
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
|
||||||
createLog(
|
if (serverInfo[0].isUpgrading) {
|
||||||
"info",
|
createLog(
|
||||||
"lst",
|
|
||||||
"serverUpdater",
|
|
||||||
`${server?.toLowerCase()}, has been updated and can now be used again.`
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
createLog(
|
|
||||||
"error",
|
"error",
|
||||||
"lst",
|
"lst",
|
||||||
"serverUpdater",
|
"serverUpdater",
|
||||||
`There was an error updating the last time the server was updated: ${error}`
|
`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.`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
resolve({
|
const scriptPath = `${process.env.DEVFOLDER}\\server\\scripts\\update.ps1 `;
|
||||||
success: true,
|
const args = [
|
||||||
message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
|
"-NoProfile",
|
||||||
});
|
"-ExecutionPolicy",
|
||||||
} else {
|
"Bypass",
|
||||||
const errorMessage = `Process exited with code ${code}`;
|
"-File",
|
||||||
resolve({
|
scriptPath,
|
||||||
success: true,
|
"-username",
|
||||||
message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
|
process.env.ADMUSER, // needs moved to somewhere else.
|
||||||
});
|
"-admpass",
|
||||||
} else {
|
process.env.ADMPASSWORD, // needs moved to somewhere else.
|
||||||
const errorMessage = `Process exited with code ${code}`;
|
"-devFolder",
|
||||||
|
process.env.DEVFOLDER,
|
||||||
|
"-server",
|
||||||
|
serverInfo[0].serverDNS,
|
||||||
|
"-serverIP",
|
||||||
|
serverInfo[0].idAddress,
|
||||||
|
"-token",
|
||||||
|
serverInfo[0].plantToken,
|
||||||
|
"-build",
|
||||||
|
`${process.env.DEVFOLDER}\\builds`,
|
||||||
|
"-location",
|
||||||
|
serverInfo[0].serverLoc,
|
||||||
|
"-obslst",
|
||||||
|
serverInfo[0].oldVersion,
|
||||||
|
"-obsBuild",
|
||||||
|
app.admConfig.oldBuild,
|
||||||
|
,
|
||||||
|
];
|
||||||
|
|
||||||
// if (count >= servers) {
|
return new Promise(async (resolve, reject) => {
|
||||||
// //onClose(code);
|
const process = spawn("powershell", args);
|
||||||
// }
|
// change the server to upgradeing
|
||||||
// if (count >= servers) {
|
await db
|
||||||
// //onClose(code);
|
.update(serverData)
|
||||||
// }
|
.set({ isUpgrading: true })
|
||||||
|
.where(eq(serverData.plantToken, server?.toLowerCase() ?? ""));
|
||||||
|
//let stdout = "";
|
||||||
|
//let stderr = "";
|
||||||
|
|
||||||
reject({
|
// Collect stdout data
|
||||||
success: false,
|
process.stdout.on("data", (data) => {
|
||||||
message: `${server?.toLowerCase()}, Has encounted an error while updating.`,
|
const output = data.toString().trim();
|
||||||
|
createLog("info", "lst", "serverUpdater", `${output}`);
|
||||||
|
//onData(output);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
reject({
|
|
||||||
success: false,
|
|
||||||
message: `${server?.toLowerCase()}, Has encounted an error while updating.`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle errors with the process itself
|
// Collect stderr data
|
||||||
process.on("error", (error) => {
|
process.stderr.on("data", (data) => {
|
||||||
//onError(err.message);
|
const output = data.toString().trim();
|
||||||
createLog("error", "lst", "serverUpdater", `${error}`);
|
createLog("info", "lst", "serverUpdater", `${output}`);
|
||||||
reject(error);
|
//onData(output);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle process close
|
||||||
|
process.on("close", async (code) => {
|
||||||
|
if (code === 0) {
|
||||||
|
// if (count >= servers) {
|
||||||
|
// //onClose(`Server completed with code: ${code}`);
|
||||||
|
// }
|
||||||
|
createLog("info", "lst", "serverUpdater", `${server}`);
|
||||||
|
|
||||||
|
//update the last build.
|
||||||
|
try {
|
||||||
|
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",
|
||||||
|
"lst",
|
||||||
|
"serverUpdater",
|
||||||
|
`There was an error updating the last time the server was updated: ${error}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve({
|
||||||
|
success: true,
|
||||||
|
message: `${server?.toLowerCase()}, has been updated and can now be used again.`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const errorMessage = `Process exited with code ${code}`;
|
||||||
|
|
||||||
|
// if (count >= servers) {
|
||||||
|
// //onClose(code);
|
||||||
|
// }
|
||||||
|
|
||||||
|
reject({
|
||||||
|
success: false,
|
||||||
|
message: `${server?.toLowerCase()}, Has encounted an error while updating.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle errors with the process itself
|
||||||
|
process.on("error", (error) => {
|
||||||
|
//onError(err.message);
|
||||||
|
createLog("error", "lst", "serverUpdater", `${error}`);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
// Handle errors with the process itself
|
|
||||||
process.on("error", (error) => {
|
|
||||||
//onError(err.message);
|
|
||||||
createLog("error", "lst", "serverUpdater", `${error}`);
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function processAllServers(devApp: string) {
|
export async function processAllServers(devApp: string) {
|
||||||
const servers = await db.select().from(serverData);
|
const servers = await db.select().from(serverData);
|
||||||
const servers = await db.select().from(serverData);
|
|
||||||
|
|
||||||
createLog(
|
createLog(
|
||||||
"info",
|
|
||||||
"lst",
|
|
||||||
"serverUpdater",
|
|
||||||
`Running the update on all servers`
|
|
||||||
);
|
|
||||||
let count = 1;
|
|
||||||
for (const server of servers) {
|
|
||||||
try {
|
|
||||||
const updateToServer = await updateServer(devApp, server.plantToken);
|
|
||||||
createLog("info", "lst", "serverUpdater", `${server.sName} was updated.`);
|
|
||||||
count = count + 1;
|
|
||||||
createLog(
|
|
||||||
"info",
|
|
||||||
"lst",
|
|
||||||
"serverUpdater",
|
|
||||||
`Running the update on all servers`
|
|
||||||
);
|
|
||||||
let count = 1;
|
|
||||||
for (const server of servers) {
|
|
||||||
try {
|
|
||||||
const updateToServer = await updateServer(devApp, server.plantToken);
|
|
||||||
createLog("info", "lst", "serverUpdater", `${server.sName} was updated.`);
|
|
||||||
count = count + 1;
|
|
||||||
|
|
||||||
//return {success: true, message: `${server.sName} was updated.`, data: updateToServer};
|
|
||||||
} catch (error: any) {
|
|
||||||
createLog(
|
|
||||||
"info",
|
"info",
|
||||||
"lst",
|
"lst",
|
||||||
"serverUpdater",
|
"serverUpdater",
|
||||||
`Error updating ${server.sName}: ${error.message}`
|
`Running the update on all servers`
|
||||||
);
|
);
|
||||||
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
|
let count = 1;
|
||||||
|
for (const server of servers) {
|
||||||
|
try {
|
||||||
|
const updateToServer = await updateServer(
|
||||||
|
devApp,
|
||||||
|
server.plantToken
|
||||||
|
);
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"lst",
|
||||||
|
"serverUpdater",
|
||||||
|
`${server.sName} was updated.`
|
||||||
|
);
|
||||||
|
count = count + 1;
|
||||||
|
|
||||||
|
//return {success: true, message: `${server.sName} was updated.`, data: updateToServer};
|
||||||
|
} catch (error: any) {
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"lst",
|
||||||
|
"serverUpdater",
|
||||||
|
`Error updating ${server.sName}: ${error.message}`
|
||||||
|
);
|
||||||
|
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//return {success: true, message: `${server.sName} was updated.`, data: updateToServer};
|
|
||||||
} catch (error: any) {
|
|
||||||
createLog(
|
|
||||||
"info",
|
|
||||||
"lst",
|
|
||||||
"serverUpdater",
|
|
||||||
`Error updating ${server.sName}: ${error.message}`
|
|
||||||
);
|
|
||||||
//return {success: false, message: `Error updating ${server.sName}: ${error.message}`};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,6 @@ import { createSSCC } from "../../../globalUtils/createSSCC.js";
|
|||||||
import { createLog } from "../../logger/logger.js";
|
import { createLog } from "../../logger/logger.js";
|
||||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||||
import { labelData } from "../../sqlServer/querys/materialHelpers/labelInfo.js";
|
import { labelData } from "../../sqlServer/querys/materialHelpers/labelInfo.js";
|
||||||
import { db } from "../../../../database/dbclient.js";
|
|
||||||
import { ocmeData } from "../../../../database/schema/ocme.js";
|
|
||||||
import { createSSCC } from "../../../globalUtils/createSSCC.js";
|
|
||||||
import { createLog } from "../../logger/logger.js";
|
|
||||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
|
||||||
import { labelData } from "../../sqlServer/querys/materialHelpers/labelInfo.js";
|
|
||||||
|
|
||||||
export const postLabelData = async (data: any) => {
|
export const postLabelData = async (data: any) => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
|||||||
21
server/services/ocp/controller/getPrinters.ts
Normal file
21
server/services/ocp/controller/getPrinters.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { db } from "../../../../database/dbclient.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
import { printers } from "../../../../database/schema/printers.js";
|
||||||
|
|
||||||
|
export const getPrinters = async () => {
|
||||||
|
const currentTime = new Date(Date.now());
|
||||||
|
|
||||||
|
const { data: printerData, error: printerError } = await tryCatch(
|
||||||
|
db.select().from(printers)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (printerError) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "there was an error getting the printers",
|
||||||
|
data: printerError,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: true, message: "Printers", data: printerData };
|
||||||
|
};
|
||||||
@@ -1,20 +1,44 @@
|
|||||||
import {db} from "../../../../database/dbclient.js";
|
import { db } from "../../../../database/dbclient.js";
|
||||||
import {manualPrinting} from "../../../../database/schema/ocpManualPrint.js";
|
import { manualPrinting } from "../../../../database/schema/ocpManualPrint.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
export const manualPrint = async (data: any) => {
|
export const manualPrint = async (manualPrint: any) => {
|
||||||
/**
|
/**
|
||||||
* add the reason we did a manual print.
|
* add the reason we did a manual print.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const manualPrintData = {
|
const manualPrintData = {
|
||||||
line: data.line,
|
line: manualPrint.line,
|
||||||
printReason: data.printReason,
|
printReason: manualPrint.printReason,
|
||||||
initials: data.initials,
|
initials: manualPrint.initials,
|
||||||
additionalComments: data?.additionalComments,
|
additionalComments: manualPrint?.additionalComments,
|
||||||
add_user: "lst",
|
add_user: "lst",
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
const { data, error } = await tryCatch(
|
||||||
const manualPrint = await db.insert(manualPrinting).values(manualPrintData);
|
db
|
||||||
} catch (error) {}
|
.insert(manualPrinting)
|
||||||
|
.values(manualPrintData)
|
||||||
|
.returning({
|
||||||
|
line: manualPrinting.line,
|
||||||
|
printReason: manualPrinting.printReason,
|
||||||
|
initials: manualPrinting.initials,
|
||||||
|
additionalComments: manualPrinting?.additionalComments,
|
||||||
|
add_user: manualPrinting.add_user,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "There was an error posting the manualPrintData",
|
||||||
|
data: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "There was an error posting the manualPrintData",
|
||||||
|
data,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
84
server/services/ocp/controller/updatePrinters.ts
Normal file
84
server/services/ocp/controller/updatePrinters.ts
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import { db } from "../../../../database/dbclient.js";
|
||||||
|
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||||
|
import { printers } from "../../../../database/schema/printers.js";
|
||||||
|
import { settings } from "../../../../database/schema/settings.js";
|
||||||
|
import axios from "axios";
|
||||||
|
import { lstAuth } from "../../../index.js";
|
||||||
|
import { prodEndpointCreation } from "../../../globalUtils/createUrl.js";
|
||||||
|
import { createLog } from "../../logger/logger.js";
|
||||||
|
import { sql } from "drizzle-orm";
|
||||||
|
|
||||||
|
export const updatePrinters = async () => {
|
||||||
|
const currentTime = new Date(Date.now());
|
||||||
|
|
||||||
|
// get the printers from prod
|
||||||
|
let url = await prodEndpointCreation(
|
||||||
|
"/public/v1.0/Administration/Printers"
|
||||||
|
);
|
||||||
|
|
||||||
|
const { data: prodPrinters, error: prodError } = await tryCatch(
|
||||||
|
axios.get(url, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Basic ${lstAuth}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (prodError) {
|
||||||
|
console.log(prodError);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "there was an error getting the printers.",
|
||||||
|
data: prodError,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// do the printer update into our db
|
||||||
|
const prodPrinterInfo = prodPrinters.data;
|
||||||
|
|
||||||
|
for (let i = 0; i < prodPrinterInfo.length; i++) {
|
||||||
|
const printerStuff: any = {
|
||||||
|
humanReadableId: prodPrinterInfo[i].humanReadableId,
|
||||||
|
name: prodPrinterInfo[i].name,
|
||||||
|
ipAddress: prodPrinterInfo[i].ipAddress,
|
||||||
|
port: prodPrinterInfo[i].port,
|
||||||
|
remark: prodPrinterInfo[i].remark,
|
||||||
|
};
|
||||||
|
const { data, error } = await tryCatch(
|
||||||
|
db
|
||||||
|
.insert(printers)
|
||||||
|
.values(printerStuff)
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: printers.humanReadableId,
|
||||||
|
set: {
|
||||||
|
//humanReadableId: prodPrinterInfo[i].humanReadableId,
|
||||||
|
name: prodPrinterInfo[i].name,
|
||||||
|
ipAddress: prodPrinterInfo[i].ipAddress,
|
||||||
|
port: prodPrinterInfo[i].port,
|
||||||
|
remark: prodPrinterInfo[i].remark,
|
||||||
|
upd_date: sql`NOW()`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"lst",
|
||||||
|
"ocp",
|
||||||
|
`${
|
||||||
|
prodPrinterInfo[i].name
|
||||||
|
} encoutered and error adding/updating ${JSON.stringify(error)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"lst",
|
||||||
|
"ocp",
|
||||||
|
`${prodPrinterInfo[i].name} were just added/updated.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return { success: true, message: "Printers were just added or updated." };
|
||||||
|
};
|
||||||
@@ -1,14 +1,21 @@
|
|||||||
import {OpenAPIHono} from "@hono/zod-openapi";
|
import { OpenAPIHono } from "@hono/zod-openapi";
|
||||||
|
|
||||||
// routes
|
// routes
|
||||||
import manualLabelLog from "./routes/manualPrintLog.js";
|
import manualLabelLog from "./routes/manualPrintLog.js";
|
||||||
|
import getPrinters from "./routes/printers/getPritners.js";
|
||||||
import {db} from "../../../database/dbclient.js";
|
import { db } from "../../../database/dbclient.js";
|
||||||
import {settings} from "../../../database/schema/settings.js";
|
import { settings } from "../../../database/schema/settings.js";
|
||||||
|
import updateprinters from "./routes/printers/updatePrinters.js";
|
||||||
|
import { updatePrinters } from "./controller/updatePrinters.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
const routes = [manualLabelLog] as const;
|
const routes = [
|
||||||
|
manualLabelLog,
|
||||||
|
//printer
|
||||||
|
getPrinters,
|
||||||
|
updateprinters,
|
||||||
|
] as const;
|
||||||
const setting = await db.select().from(settings);
|
const setting = await db.select().from(settings);
|
||||||
|
|
||||||
const appRoutes = routes.forEach((route) => {
|
const appRoutes = routes.forEach((route) => {
|
||||||
@@ -16,7 +23,13 @@ const appRoutes = routes.forEach((route) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.all("/ocp/*", (c) => {
|
app.all("/ocp/*", (c) => {
|
||||||
return c.json({success: false, message: "You have encounters a ocp route that dose not exist."});
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: "You have encounters a ocp route that dose not exist.",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// run the printer update on restart just to keep everything good
|
||||||
|
updatePrinters();
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
@@ -1,18 +1,21 @@
|
|||||||
// an external way to creating logs
|
// an external way to creating logs
|
||||||
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
import {apiHit} from "../../../globalUtils/apiHits.js";
|
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||||
import {responses} from "../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||||
import type {User} from "../../../types/users.js";
|
import type { User } from "../../../types/users.js";
|
||||||
import {verify} from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
import {manualPrint} from "../controller/manualLabelLog.js";
|
import { manualPrint } from "../controller/manualLabelLog.js";
|
||||||
import {authMiddleware} from "../../auth/middleware/authMiddleware.js";
|
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono({strict: false});
|
const app = new OpenAPIHono({ strict: false });
|
||||||
const CreateLog = z.object({
|
const CreateLog = z.object({
|
||||||
line: z.string().openapi({example: "info"}),
|
line: z.string().openapi({ example: "info" }),
|
||||||
initials: z.string().openapi({example: "server"}),
|
initials: z.string().openapi({ example: "server" }),
|
||||||
printReason: z.string().openapi({example: "This is a new log posted"}),
|
printReason: z.string().openapi({ example: "This is a new log posted" }),
|
||||||
additionalComments: z.string().optional().openapi({example: "Some reason why we did this."}),
|
additionalComments: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: "Some reason why we did this." }),
|
||||||
});
|
});
|
||||||
|
|
||||||
app.openapi(
|
app.openapi(
|
||||||
@@ -24,32 +27,33 @@ app.openapi(
|
|||||||
//middleware: authMiddleware,
|
//middleware: authMiddleware,
|
||||||
//description: "This might be a temp soltuin during the transtion between versions",
|
//description: "This might be a temp soltuin during the transtion between versions",
|
||||||
request: {
|
request: {
|
||||||
body: {content: {"application/json": {schema: CreateLog}}},
|
body: { content: { "application/json": { schema: CreateLog } } },
|
||||||
},
|
},
|
||||||
responses: responses(),
|
responses: responses(),
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const body = await c.req.json();
|
const body = await c.req.json();
|
||||||
apiHit(c, {endpoint: `api/logger/logs/id`});
|
apiHit(c, { endpoint: `api/logger/logs/id` });
|
||||||
// const authHeader = c.req.header("Authorization");
|
|
||||||
|
|
||||||
// const token = authHeader?.split("Bearer ")[1] || "";
|
|
||||||
// let user: User;
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// const payload = await verify(token, process.env.JWT_SECRET!);
|
|
||||||
// user = payload.user as User;
|
|
||||||
// } catch (error) {
|
|
||||||
// console.log(error);
|
|
||||||
// return c.json({message: "Unauthorized"}, 401);
|
|
||||||
// }
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//const data = {...body, add_user: user.username};
|
//const data = {...body, add_user: user.username};
|
||||||
await manualPrint(body);
|
const printLog: any = await manualPrint(body);
|
||||||
return c.json({success: true, message: "Manual Print was added.", data: []}, 200);
|
return c.json(
|
||||||
|
{
|
||||||
|
success: printLog.success,
|
||||||
|
message: printLog.message,
|
||||||
|
data: printLog.data ?? [],
|
||||||
|
},
|
||||||
|
200
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return c.json({success: false, message: "There was an error clearing the log.", data: error}, 400);
|
return c.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "There was an error clearing the log.",
|
||||||
|
data: error,
|
||||||
|
},
|
||||||
|
400
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
50
server/services/ocp/routes/printers/getPritners.ts
Normal file
50
server/services/ocp/routes/printers/getPritners.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
// an external way to creating logs
|
||||||
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { getPrinters } from "../../controller/getPrinters.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
const CreateLog = z.object({
|
||||||
|
line: z.string().openapi({ example: "info" }),
|
||||||
|
initials: z.string().openapi({ example: "server" }),
|
||||||
|
printReason: z.string().openapi({ example: "This is a new log posted" }),
|
||||||
|
additionalComments: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: "Some reason why we did this." }),
|
||||||
|
});
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["ocp"],
|
||||||
|
summary: "Prints a label.",
|
||||||
|
method: "get",
|
||||||
|
path: "/getprinters",
|
||||||
|
//middleware: authMiddleware,
|
||||||
|
//description: "This might be a temp soltuin during the transtion between versions",
|
||||||
|
request: {
|
||||||
|
body: { content: { "application/json": { schema: CreateLog } } },
|
||||||
|
},
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
const { data: printData, error: printError } = await tryCatch(
|
||||||
|
getPrinters()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (printError) {
|
||||||
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: "There was an error getting the printers",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
success: printData.success,
|
||||||
|
message: printData.message,
|
||||||
|
data: printData.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
51
server/services/ocp/routes/printers/updatePrinters.ts
Normal file
51
server/services/ocp/routes/printers/updatePrinters.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// an external way to creating logs
|
||||||
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { getPrinters } from "../../controller/getPrinters.js";
|
||||||
|
import { updatePrinters } from "../../controller/updatePrinters.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono({ strict: false });
|
||||||
|
const CreateLog = z.object({
|
||||||
|
line: z.string().openapi({ example: "info" }),
|
||||||
|
initials: z.string().openapi({ example: "server" }),
|
||||||
|
printReason: z.string().openapi({ example: "This is a new log posted" }),
|
||||||
|
additionalComments: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.openapi({ example: "Some reason why we did this." }),
|
||||||
|
});
|
||||||
|
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["ocp"],
|
||||||
|
summary: "Prints a label.",
|
||||||
|
method: "get",
|
||||||
|
path: "/updateprinters",
|
||||||
|
//middleware: authMiddleware,
|
||||||
|
//description: "This might be a temp soltuin during the transtion between versions",
|
||||||
|
request: {
|
||||||
|
body: { content: { "application/json": { schema: CreateLog } } },
|
||||||
|
},
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
const { data: printData, error: printError } = await tryCatch(
|
||||||
|
updatePrinters()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (printError) {
|
||||||
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: "There was an error getting the printers",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
success: printData.success,
|
||||||
|
message: printData.message,
|
||||||
|
data: printData.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
Reference in New Issue
Block a user