perf(lst): more migrations

This commit is contained in:
2025-02-24 20:59:35 -06:00
parent c92d74647b
commit babd7beb06
16 changed files with 467 additions and 28 deletions

View File

@@ -8,17 +8,18 @@ import {OpenAPIHono} from "@hono/zod-openapi";
import auth from "./services/auth/authService";
import scalar from "./services/general/route/scalar";
import apiHits from "./services/general/route/apitHits";
import getModules from "./services/general/route/getModules";
// services
import {ocmeService} from "./services/ocme/ocmeServer";
import system from "./services/system/systemServer";
const app = new OpenAPIHono();
app.use("*", logger());
const allowedOrigins = ["http://localhost:3000", "http://localhost:4000", "http://localhost:5173"];
app.use(
"*",
cors({
origin: `http://localhost:5173`,
origin: allowedOrigins,
allowHeaders: ["X-Custom-Header", "Upgrade-Insecure-Requests"],
allowMethods: ["POST", "GET", "OPTIONS"],
exposeHeaders: ["Content-Length", "X-Kuma-Revision"],
@@ -36,11 +37,11 @@ app.doc("/api", {
});
// as we dont want to change ocme again well use a proxy to this
app.all("/ocme/*", async (c) => {
return ocmeService(c);
});
// app.all("/ocme/*", async (c) => {
// return ocmeService(c);
// });
const routes = [scalar, auth, apiHits, getModules] as const;
const routes = [scalar, auth, apiHits, system] as const;
routes.forEach((route) => {
app.route("/api/", route);

View File

@@ -15,12 +15,13 @@ export async function login(
): Promise<{token: string; user: {user_id: string; username: string}}> {
const user = await db.select().from(users).where(eq(users.username, username));
console.log(user);
if (user.length === 0) {
throw new Error("Invalid or Missing user");
}
// check the password
const checkedPass = await checkPassword(password, user[0]?.password);
console.log(checkedPass);
//console.log(checkedPass);
if (!checkedPass) {
throw new Error("Invalid Password");
}
@@ -36,8 +37,9 @@ export async function login(
username: user[0].username,
email: user[0].email,
roles: roles || null,
role: user[0].role || null, // this should be removed onces full migration to v2 is completed
};
const token = sign({user: userData}, secret, {expiresIn: expiresIn * 60});
return {token, user: {user_id: user[0].user_id, username: user[0].username}};
return {token, user: userData};
}

View File

@@ -75,7 +75,6 @@ app.openapi(route, async (c) => {
);
}
const {token, user} = await login(username.toLowerCase(), password);
try {
const {token, user} = await login(username.toLowerCase(), password);

View File

@@ -1,10 +1,16 @@
import bcrypt from "bcrypt";
export const checkPassword = async (currentPassword: string, dbPassword: string) => {
let decyptPass = "";
try {
decyptPass = atob(dbPassword);
} catch (error) {
console.log(error);
}
// encypt password
const pass: string | undefined = process.env.SECRET;
const checked = bcrypt.compareSync(pass + currentPassword, dbPassword);
const checked = bcrypt.compareSync(pass + currentPassword, decyptPass);
return checked;
};

View File

@@ -10,7 +10,7 @@ export const createPassword = async (password: string) => {
} else {
pass = bcrypt.hashSync(pass + password, parseInt(salt));
// pass = btoa(pass);
pass = btoa(pass);
}
return pass;

View File

@@ -52,11 +52,11 @@ app.get(
baseServerURL: "https://scalar.com",
servers: [
{
url: "http://usday1vms006:3000",
url: `http://usday1vms006:${process.env.SERVER_PORT}`,
description: "Production",
},
{
url: "http://localhost:3000",
url: `http://localhost:${process.env.SERVER_PORT}`,
description: "dev server",
},
],

View File

@@ -38,11 +38,6 @@ app.openapi(
},
}),
async (c) => {
//const data = await c.req.json();
//apiHit(data);
// get the modules that are active
let module: any = [];
try {
module = await db.select().from(modules).where(eq(modules.active, true));

View File

@@ -0,0 +1,7 @@
import {OpenAPIHono} from "@hono/zod-openapi";
import modules from "./route/modules";
const app = new OpenAPIHono().route("system/module", modules);
export default app;