Add analysis trigger
This commit is contained in:
50
server.ts
50
server.ts
@@ -2,7 +2,7 @@ import "source-map-support/register";
|
||||
import bodyParser from "body-parser";
|
||||
import compression from "compression";
|
||||
import cors from "cors";
|
||||
import dotenv from "dotenv";
|
||||
import dotenv, { config } from "dotenv";
|
||||
import express, { Express } from "express";
|
||||
import helmet from "helmet";
|
||||
import morgan from "morgan";
|
||||
@@ -30,13 +30,13 @@ dotenv.config({
|
||||
});
|
||||
|
||||
// Global error handlers
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error('Uncaught Exception:', error);
|
||||
process.on("uncaughtException", (error) => {
|
||||
console.error("Uncaught Exception:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||
process.on("unhandledRejection", (reason, promise) => {
|
||||
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@@ -121,6 +121,46 @@ const morganMiddleware = morgan("combined", {
|
||||
});
|
||||
app.use(morganMiddleware);
|
||||
|
||||
//Asynchronously check the headers for a bodyshopid. If it exists, write it to a json file in the root directory. Only do this if the bodyshopid has not already been logged once since server start.
|
||||
const loggedBodyshopIds = new Set<string>();
|
||||
|
||||
app.use((req, res, next) => {
|
||||
//Asynchronously check the headers for a bodyshopid. If it exists, write it to a json file in the root directory. Only do this if the bodyshopid has not already been logged once since server start.
|
||||
const bodyshopId = req.headers.bodyshopid as string;
|
||||
|
||||
console.log("*** ~ loggedBodyshopIds:", loggedBodyshopIds);
|
||||
if (bodyshopId && !loggedBodyshopIds.has(bodyshopId)) {
|
||||
loggedBodyshopIds.add(bodyshopId);
|
||||
|
||||
// Asynchronously write to file without blocking the request
|
||||
(async () => {
|
||||
try {
|
||||
const fs = await import("fs/promises");
|
||||
const filePath = path.join(FolderPaths.Root, "config.json");
|
||||
|
||||
let existingIds: string[] = [];
|
||||
try {
|
||||
const fileContent = await fs.readFile(filePath, "utf-8");
|
||||
const configFile = JSON.parse(fileContent);
|
||||
existingIds = configFile.bodyshopIds || [];
|
||||
} catch {
|
||||
// File doesn't exist or is invalid, start with empty array
|
||||
}
|
||||
|
||||
if (!existingIds.includes(bodyshopId)) {
|
||||
existingIds.push(bodyshopId);
|
||||
await fs.writeFile(filePath, JSON.stringify({ bodyshopIds: existingIds }, null, 2));
|
||||
logger.info(`Logged new bodyshop ID: ${bodyshopId}`);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Failed to log bodyshop ID:", error);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
// Job endpoints
|
||||
app.post("/jobs/list", ValidateImsToken, validateJobRequest, JobsListMedia);
|
||||
app.post("/jobs/upload", ValidateImsToken, JobMediaUploadMulter.array("file"), validateJobRequest, jobsUploadMedia);
|
||||
|
||||
Reference in New Issue
Block a user