From 78adca7091e7bccf02ce5d850ba4d9dfae50f1f9 Mon Sep 17 00:00:00 2001 From: Archben Date: Wed, 11 Mar 2026 04:44:11 +0000 Subject: [PATCH] Updates --- bun.lock | 8 +-- package.json | 4 +- .../auth/login/(partials)/login-form.tsx | 4 +- src/db/db-schema.js | 1 - src/db/types.ts | 6 +-- src/functions/auth/login-user.ts | 8 +-- src/functions/ttyd/grab-ttyd-service-info.ts | 7 ++- src/layouts/admin/(partials)/header-user.tsx | 52 ++++++++++++++++--- src/layouts/admin/header.tsx | 7 ++- src/pages/admin/users/index.tsx | 12 ++++- src/pages/api/auth/signup.ts | 8 +-- src/pages/auth/logout.tsx | 2 +- src/types/index.ts | 2 + src/websocket/(utils)/kill-all-ttyd-ports.ts | 9 ++-- 14 files changed, 94 insertions(+), 36 deletions(-) diff --git a/bun.lock b/bun.lock index a9a30ce..c59a485 100644 --- a/bun.lock +++ b/bun.lock @@ -5,9 +5,9 @@ "": { "name": "turboci-admin", "dependencies": { - "@moduletrace/bun-sqlite": "^1.0.9", + "@moduletrace/bun-sqlite": "^1.0.10", "@moduletrace/datasquirel": "^5.7.57", - "@moduletrace/nsqlite": "^1.0.9", + "@moduletrace/nsqlite": "^1.0.10", "better-sqlite3": "^12.6.2", "bun": "^1.3.10", "dayjs": "^1.11.19", @@ -162,11 +162,11 @@ "@mdx-js/react": ["@mdx-js/react@3.1.1", "", { "dependencies": { "@types/mdx": "^2.0.0" }, "peerDependencies": { "@types/react": ">=16", "react": ">=16" } }, "sha512-f++rKLQgUVYDAtECQ6fn/is15GkEH9+nZPM3MS0RcxVqoTfawHvDlSCH7JbMhAM6uJ32v3eXLvLmLvjGu7PTQw=="], - "@moduletrace/bun-sqlite": ["@moduletrace/bun-sqlite@1.0.9", "https://git.tben.me/api/packages/Moduletrace/npm/%40moduletrace%2Fbun-sqlite/-/1.0.9/bun-sqlite-1.0.9.tgz", { "dependencies": { "@inquirer/prompts": "^8.3.0", "chalk": "^5.6.2", "commander": "^14.0.3", "inquirer": "^13.3.0", "lodash": "^4.17.23", "mysql": "^2.18.1", "sqlite-vec": "^0.1.7-alpha.2" }, "peerDependencies": { "typescript": "^5" }, "bin": { "bun-sqlite": "dist/commands/index.js" } }, "sha512-fZiXGTmxKPHEAGNSWm04dRoUdb1gehTYRZXyfIEH2rSTa56dXoFVw2B+AvXydbM2XcaykVaOLLL1sqMEhsZZUw=="], + "@moduletrace/bun-sqlite": ["@moduletrace/bun-sqlite@1.0.10", "https://git.tben.me/api/packages/Moduletrace/npm/%40moduletrace%2Fbun-sqlite/-/1.0.10/bun-sqlite-1.0.10.tgz", { "dependencies": { "@inquirer/prompts": "^8.3.0", "chalk": "^5.6.2", "commander": "^14.0.3", "inquirer": "^13.3.0", "lodash": "^4.17.23", "mysql": "^2.18.1", "sqlite-vec": "^0.1.7-alpha.2" }, "peerDependencies": { "typescript": "^5" }, "bin": { "bun-sqlite": "dist/commands/index.js" } }, "sha512-CbbWekNvCnSLPomXIoHgJp+6Kb2Rfyt3YhovqOBLk/mPOKUsS0jFSNE6tVokUIEiCu3i4b23HbE2auMHTbZQqA=="], "@moduletrace/datasquirel": ["@moduletrace/datasquirel@5.7.57", "https://git.tben.me/api/packages/Moduletrace/npm/%40moduletrace%2Fdatasquirel/-/5.7.57/datasquirel-5.7.57.tgz", { "dependencies": { "@types/ace": "^0.0.52", "@types/lodash": "^4.17.13", "@types/next": "^9.0.0", "@types/node": "^22.7.5", "@types/nodemailer": "^6.4.17", "@types/react": "^18.2.21", "@types/react-dom": "^19.0.0", "@types/tinymce": "^4.6.9", "dotenv": "^16.3.1", "generate-password": "^1.7.1", "google-auth-library": "^9.15.0", "inquirer": "^12.5.2", "lodash": "^4.17.21", "mariadb": "^3.4.4", "nodemailer": "^6.9.14", "sanitize-html": "^2.13.1", "sql-formatter": "^15.6.10" }, "bin": { "dsql-dump": "dist/engine/dump.js", "dsql-schema-to-typedef": "dist/engine/schema-to-typedef.js", "dsql-watch": "dist/engine/dsql.js" } }, "sha512-tPNfhMIwdptKjmraVqxj/qZ5yrO4QUZ/QxwZE+jIFj37UnUCXZOfF6yVWFClsqn2fNAjU2NDqrwC9w65ZzsmKg=="], - "@moduletrace/nsqlite": ["@moduletrace/nsqlite@1.0.9", "https://git.tben.me/api/packages/Moduletrace/npm/%40moduletrace%2Fnsqlite/-/1.0.9/nsqlite-1.0.9.tgz", { "dependencies": { "@inquirer/prompts": "^8.3.0", "better-sqlite3": "^12.6.2", "chalk": "^5.6.2", "commander": "^14.0.3", "inquirer": "^13.3.0", "lodash": "^4.17.23", "mysql": "^2.18.1", "sqlite-vec": "^0.1.7-alpha.2" }, "peerDependencies": { "typescript": "^5" }, "bin": { "nsqlite": "dist/commands/index.js" } }, "sha512-+iAQUgcMTvQnlTzzKoLkms2KA0zsZ1TsjeLSS5f+pLFEfkJKbYkgf4JIqq6Jgi5p1d5GYeLqc6qjR3onLorOWQ=="], + "@moduletrace/nsqlite": ["@moduletrace/nsqlite@1.0.10", "https://git.tben.me/api/packages/Moduletrace/npm/%40moduletrace%2Fnsqlite/-/1.0.10/nsqlite-1.0.10.tgz", { "dependencies": { "@inquirer/prompts": "^8.3.0", "better-sqlite3": "^12.6.2", "chalk": "^5.6.2", "commander": "^14.0.3", "inquirer": "^13.3.0", "lodash": "^4.17.23", "mysql": "^2.18.1", "sqlite-vec": "^0.1.7-alpha.2" }, "peerDependencies": { "typescript": "^5" }, "bin": { "nsqlite": "dist/commands/index.js" } }, "sha512-WrY4bvV8kt0TkQdwh4m3rME12MXW1IEModyzia47srw+LtpORSvqI1AYFtsMM/XNCfBqrTc/UnzxFGmxp6FoKg=="], "@next/env": ["@next/env@14.2.35", "", {}, "sha512-DuhvCtj4t9Gwrx80dmz2F4t/zKQ4ktN8WrMwOuVzkJfBilwAwGr6v16M5eI8yCuZ63H9TTuEU09Iu2HqkzFPVQ=="], diff --git a/package.json b/package.json index 1578e64..3d02477 100644 --- a/package.json +++ b/package.json @@ -20,9 +20,9 @@ "build": "next build" }, "dependencies": { - "@moduletrace/bun-sqlite": "^1.0.9", + "@moduletrace/bun-sqlite": "^1.0.10", "@moduletrace/datasquirel": "^5.7.57", - "@moduletrace/nsqlite": "^1.0.9", + "@moduletrace/nsqlite": "^1.0.10", "better-sqlite3": "^12.6.2", "bun": "^1.3.10", "dayjs": "^1.11.19", diff --git a/src/components/pages/auth/login/(partials)/login-form.tsx b/src/components/pages/auth/login/(partials)/login-form.tsx index 43a33d6..9b416d4 100644 --- a/src/components/pages/auth/login/(partials)/login-form.tsx +++ b/src/components/pages/auth/login/(partials)/login-form.tsx @@ -57,10 +57,10 @@ export default function LoginForm() { placeholder="Password" title="Password" type="password" - changeHandler={(v) => { + onChange={(e) => { setLoginData((prev) => ({ ...prev, - password: v, + password: e.target.value, })); }} validity={ diff --git a/src/db/db-schema.js b/src/db/db-schema.js index a93018c..3987e35 100644 --- a/src/db/db-schema.js +++ b/src/db/db-schema.js @@ -4,7 +4,6 @@ * @type {import("@moduletrace/nsqlite/dist/types").NSQLITE_DatabaseSchemaType} */ const schema = { - dbName: "test-db", tables: [ { tableName: "users", diff --git a/src/db/types.ts b/src/db/types.ts index d5c7917..0906a04 100644 --- a/src/db/types.ts +++ b/src/db/types.ts @@ -3,7 +3,7 @@ export const NSQLiteTables = [ "users_ports", ] as const -export type NSQLITE_TEST_DB_USERS = { +export type NSQLITE_TURBOCI_ADMIN_USERS = { /** * The unique identifier of the record. */ @@ -26,7 +26,7 @@ export type NSQLITE_TEST_DB_USERS = { all_deployment_access?: number; } -export type NSQLITE_TEST_DB_USERS_PORTS = { +export type NSQLITE_TURBOCI_ADMIN_USERS_PORTS = { /** * The unique identifier of the record. */ @@ -43,4 +43,4 @@ export type NSQLITE_TEST_DB_USERS_PORTS = { port?: number; } -export type NSQLITE_TEST_DB_ALL_TYPEDEFS = NSQLITE_TEST_DB_USERS & NSQLITE_TEST_DB_USERS_PORTS \ No newline at end of file +export type NSQLITE_TURBOCI_ADMIN_ALL_TYPEDEFS = NSQLITE_TURBOCI_ADMIN_USERS & NSQLITE_TURBOCI_ADMIN_USERS_PORTS \ No newline at end of file diff --git a/src/functions/auth/login-user.ts b/src/functions/auth/login-user.ts index 0738063..92f87c8 100644 --- a/src/functions/auth/login-user.ts +++ b/src/functions/auth/login-user.ts @@ -1,7 +1,7 @@ import { NextApiResponse } from "next"; import { ServerResponse } from "http"; import NSQLite from "@moduletrace/nsqlite"; -import { NSQLITE_TEST_DB_USERS, NSQLiteTables } from "../../db/types"; +import { NSQLITE_TURBOCI_ADMIN_USERS, NSQLiteTables } from "../../db/types"; import { User } from "../../types"; import { setCookie } from "../../utils/cookies-actions"; import { EJSON } from "../../exports/client-exports"; @@ -24,11 +24,11 @@ export default async function loginUser({ password, email_or_username, }: Params): Promise { - let fetched_user: NSQLITE_TEST_DB_USERS | undefined; + let fetched_user: NSQLITE_TURBOCI_ADMIN_USERS | undefined; if (user_id) { const user_res = await NSQLite.select< - NSQLITE_TEST_DB_USERS, + NSQLITE_TURBOCI_ADMIN_USERS, (typeof NSQLiteTables)[number] >({ table: "users", @@ -44,7 +44,7 @@ export default async function loginUser({ if (email_or_username) { const user_res = await NSQLite.select< - NSQLITE_TEST_DB_USERS, + NSQLITE_TURBOCI_ADMIN_USERS, (typeof NSQLiteTables)[number] >({ table: "users", diff --git a/src/functions/ttyd/grab-ttyd-service-info.ts b/src/functions/ttyd/grab-ttyd-service-info.ts index 8004ec1..f4aa0ae 100644 --- a/src/functions/ttyd/grab-ttyd-service-info.ts +++ b/src/functions/ttyd/grab-ttyd-service-info.ts @@ -1,4 +1,7 @@ -import { NSQLITE_TEST_DB_USERS_PORTS, NSQLiteTables } from "@/src/db/types"; +import { + NSQLITE_TURBOCI_ADMIN_USERS_PORTS, + NSQLiteTables, +} from "@/src/db/types"; import { NormalizedServerObject, ParsedDeploymentServiceConfig, @@ -74,7 +77,7 @@ export default async function grabTtydServerInfo({ const connected_user_data = grabConnectedWebsocketUserdata({ user }); await BunSQLite.insert< - NSQLITE_TEST_DB_USERS_PORTS, + NSQLITE_TURBOCI_ADMIN_USERS_PORTS, (typeof NSQLiteTables)[number] >({ data: [{ user_id: user.id, port: available_port }], diff --git a/src/layouts/admin/(partials)/header-user.tsx b/src/layouts/admin/(partials)/header-user.tsx index 61a753e..201ca27 100644 --- a/src/layouts/admin/(partials)/header-user.tsx +++ b/src/layouts/admin/(partials)/header-user.tsx @@ -2,31 +2,67 @@ import { AppContext } from "@/src/pages/_app"; import Dropdown from "@/twui/components/elements/Dropdown"; import LinkList from "@/twui/components/elements/LinkList"; import LucideIcon from "@/twui/components/elements/lucide-icon"; +import Paper from "@/twui/components/elements/Paper"; +import Divider from "@/twui/components/layout/Divider"; import Img from "@/twui/components/layout/Img"; import Row from "@/twui/components/layout/Row"; import Span from "@/twui/components/layout/Span"; import { useContext } from "react"; +import { twMerge } from "tailwind-merge"; export default function HeaderUser() { const { pageProps } = useContext(AppContext); const { user } = pageProps; + const ICON_SIZE = 35; + return ( - {`${user.first_name} + + {user.image_thumbnail ? ( + {`${user.first_name} + ) : ( +
+ )} {user.first_name} } + position="bottom-right" > - + + , + }, + { + title: `Logout`, + url: `/auth/logout`, + }, + ]} + className="flex-col items-stretch w-full" + /> + ); } diff --git a/src/layouts/admin/header.tsx b/src/layouts/admin/header.tsx index 32737e2..5cd5d93 100644 --- a/src/layouts/admin/header.tsx +++ b/src/layouts/admin/header.tsx @@ -1,6 +1,7 @@ import Logo from "@/src/components/general/logo"; import Row from "@/twui/components/layout/Row"; import { PropsWithChildren } from "react"; +import HeaderUser from "./(partials)/header-user"; type Props = PropsWithChildren & {}; @@ -15,7 +16,11 @@ export default function Header({ children }: Props) { {/* */} - + + + + + ); diff --git a/src/pages/admin/users/index.tsx b/src/pages/admin/users/index.tsx index 05e40f7..3e5dd7f 100644 --- a/src/pages/admin/users/index.tsx +++ b/src/pages/admin/users/index.tsx @@ -1,6 +1,8 @@ import Main from "@/src/components/pages/admin/users"; +import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types"; import defaultAdminProps from "@/src/functions/pages/admin/default-admin-props"; import Layout from "@/src/layouts/admin"; +import NSQLite from "@moduletrace/nsqlite"; import { GetServerSideProps } from "next"; export default function AdminDashboard() { @@ -19,7 +21,15 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return `/admin`; } - return {}; + const users_res = await NSQLite.select( + { + table: "users", + }, + ); + + return { + deployment_users: users_res.payload, + }; }, }); }; diff --git a/src/pages/api/auth/signup.ts b/src/pages/api/auth/signup.ts index 6a4629c..d7427f9 100644 --- a/src/pages/api/auth/signup.ts +++ b/src/pages/api/auth/signup.ts @@ -1,4 +1,4 @@ -import { NSQLITE_TEST_DB_USERS, NSQLiteTables } from "@/src/db/types"; +import { NSQLITE_TURBOCI_ADMIN_USERS, NSQLiteTables } from "@/src/db/types"; import { APIReqObject } from "@/src/types"; import loginUser from "@/src/functions/auth/login-user"; import hashPassword from "@moduletrace/datasquirel/dist/package-shared/functions/dsql/hashPassword"; @@ -29,7 +29,7 @@ export default async function handler( } const existing_users_res = await NSQLite.select< - NSQLITE_TEST_DB_USERS, + NSQLITE_TURBOCI_ADMIN_USERS, (typeof NSQLiteTables)[number] >({ table: "users", @@ -47,7 +47,7 @@ export default async function handler( const new_user_password = hashPassword({ password }); const new_user_insert_res = await NSQLite.insert< - NSQLITE_TEST_DB_USERS, + NSQLITE_TURBOCI_ADMIN_USERS, (typeof NSQLiteTables)[number] >({ data: [ @@ -71,7 +71,7 @@ export default async function handler( } const newly_inserted_user_res = await NSQLite.select< - NSQLITE_TEST_DB_USERS, + NSQLITE_TURBOCI_ADMIN_USERS, (typeof NSQLiteTables)[number] >({ table: "users", diff --git a/src/pages/auth/logout.tsx b/src/pages/auth/logout.tsx index 97d5752..5c6c561 100644 --- a/src/pages/auth/logout.tsx +++ b/src/pages/auth/logout.tsx @@ -16,7 +16,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => { return { redirect: { - destination: `/login`, + destination: `/auth/login`, statusCode: 307, }, }; diff --git a/src/types/index.ts b/src/types/index.ts index 52aeb66..1ddc821 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -3,6 +3,7 @@ import { DATASQUIREL_LoggedInUser } from "@moduletrace/datasquirel/dist/package- import useAppInit from "../hooks/use-app-init"; import { ServerWebSocket } from "bun"; import { ChildProcess } from "child_process"; +import { NSQLITE_TURBOCI_ADMIN_USERS } from "../db/types"; export type User = DATASQUIREL_LoggedInUser & { super_admin?: 0 | 1; @@ -196,6 +197,7 @@ export type PagePropsType = { children_services?: ParsedDeploymentServiceConfig[] | null; ws_url?: string | null; host?: string | null; + deployment_users?: NSQLITE_TURBOCI_ADMIN_USERS[] | null; }; export type APIReqObject = { diff --git a/src/websocket/(utils)/kill-all-ttyd-ports.ts b/src/websocket/(utils)/kill-all-ttyd-ports.ts index 268c513..25e2ad1 100644 --- a/src/websocket/(utils)/kill-all-ttyd-ports.ts +++ b/src/websocket/(utils)/kill-all-ttyd-ports.ts @@ -1,5 +1,8 @@ import { AppData } from "@/src/data/app-data"; -import { NSQLITE_TEST_DB_USERS_PORTS, NSQLiteTables } from "@/src/db/types"; +import { + NSQLITE_TURBOCI_ADMIN_USERS_PORTS, + NSQLiteTables, +} from "@/src/db/types"; import { User } from "@/src/types"; import BunSQLite from "@moduletrace/bun-sqlite"; import { execSync, ExecSyncOptions } from "child_process"; @@ -11,7 +14,7 @@ type Params = { export default async function killAllTtydPorts({ user }: Params) { const user_ports_res = await BunSQLite.select< - NSQLITE_TEST_DB_USERS_PORTS, + NSQLITE_TURBOCI_ADMIN_USERS_PORTS, (typeof NSQLiteTables)[number] >({ table: "users_ports", @@ -28,7 +31,7 @@ export default async function killAllTtydPorts({ user }: Params) { await killPort({ port: user_port.port }); await BunSQLite.delete< - NSQLITE_TEST_DB_USERS_PORTS, + NSQLITE_TURBOCI_ADMIN_USERS_PORTS, (typeof NSQLiteTables)[number] >({ table: "users_ports",