diff --git a/bun-sqlite.config.ts b/bun-sqlite.config.ts index d3d961a..a090930 100644 --- a/bun-sqlite.config.ts +++ b/bun-sqlite.config.ts @@ -1,4 +1,4 @@ -import type { BunSQLiteConfig } from "@moduletrace/bun-sqlite/dist/types"; +import type { BunSQLiteConfig } from "@moduletrace/bun-sqlite/types"; const config: BunSQLiteConfig = { db_name: "wgui", diff --git a/db/schema.ts b/db/schema.ts index a3c5172..096fc32 100644 --- a/db/schema.ts +++ b/db/schema.ts @@ -6,7 +6,7 @@ import { import { MediaParadigms, MediaTypes } from "@/src/dict/media-dict"; import { UserTypes } from "@/src/dict/user-types-dict"; import { Variables } from "@/src/dict/variables-dict"; -import type { BUN_SQLITE_DatabaseSchemaType } from "@moduletrace/bun-sqlite/dist/types"; +import type { BUN_SQLITE_DatabaseSchemaType } from "@moduletrace/bun-sqlite/types"; const schema: BUN_SQLITE_DatabaseSchemaType = { tables: [ diff --git a/src/email/root.tsx b/src/email/root.tsx deleted file mode 100644 index 0a678f6..0000000 --- a/src/email/root.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import type { PropsWithChildren } from "react"; - -type Props = PropsWithChildren & {}; - -export default function EmailRoot({ children }: Props) { - const divider = ( -
- ); - - return ( -
- - Wireguard UI Mailer - - {divider} -
{children}
- {divider} -
- ); -} diff --git a/src/functions/backend/db/check-allowed-joins.ts b/src/functions/backend/db/check-allowed-joins.ts index b0d6e70..109f409 100644 --- a/src/functions/backend/db/check-allowed-joins.ts +++ b/src/functions/backend/db/check-allowed-joins.ts @@ -1,7 +1,7 @@ import type { BUN_SQLITE_WGUI_ALL_TYPEDEFS } from "@/db/types/db"; import type { TableType } from "@/src/types"; import uniqueStringArr from "@/src/utils/unique-string-arr"; -import type { ServerQueryParam } from "@moduletrace/bun-sqlite/dist/types"; +import type { ServerQueryParam } from "@moduletrace/bun-sqlite/types"; import BunSQLite from "@moduletrace/bun-sqlite"; import type { APIResponseObject } from "@moduletrace/bunext/types"; import _ from "lodash"; diff --git a/src/functions/backend/db/clients/grab-clients.ts b/src/functions/backend/db/clients/grab-clients.ts index 26e9308..13d0b00 100644 --- a/src/functions/backend/db/clients/grab-clients.ts +++ b/src/functions/backend/db/clients/grab-clients.ts @@ -1,7 +1,7 @@ import { AppData } from "@/src/data/app-data"; import type { ApiReqParams, SQLInsertGenValueType } from "@/src/types"; import type { BUN_SQLITE_WGUI_CLIENTS_JOIN } from "@/src/types/sql-joins"; -import type { ServerQueryParamOrder } from "@moduletrace/bun-sqlite/dist/types"; +import type { ServerQueryParamOrder } from "@moduletrace/bun-sqlite/types"; import BunSQLite from "@moduletrace/bun-sqlite"; import type { APIResponseObject } from "@moduletrace/bunext/types"; diff --git a/src/functions/backend/db/users/media/file-to-text.ts b/src/functions/backend/db/users/media/file-to-text.ts deleted file mode 100644 index 7078b9c..0000000 --- a/src/functions/backend/db/users/media/file-to-text.ts +++ /dev/null @@ -1,82 +0,0 @@ -import TurndownService from "turndown"; -import { extractText, getDocumentProxy } from "unpdf"; -import mammoth from "mammoth"; -import * as XLSX from "xlsx"; -import type { FileType } from "onnxruntime-node"; -import bufferFromUrl from "@/src/utils/buffer-from-url"; - -const turndownService = new TurndownService({ - headingStyle: "atx", - codeBlockStyle: "fenced", -}); - -type Params = { - file_stream?: Buffer; - file_path?: string; - file_type?: FileType; - url?: string; -}; - -export default async function fileToText({ - file_type, - file_stream, - file_path, - url, -}: Params): Promise { - let buffer: Buffer | undefined; - let ext: string; - - if (url) { - const result = await bufferFromUrl(url); - buffer = result.buffer; - ext = result.ext; - } else { - buffer = file_path - ? Buffer.from(await Bun.file(file_path).arrayBuffer()) - : file_stream; - ext = (file_type || file_path?.split(".").pop() || "txt") - .toString() - .toLowerCase(); - } - - if (!buffer) return undefined; - - switch (ext) { - case "docx": { - const { value: html } = await mammoth.convertToHtml({ buffer }); - return turndownService.turndown(html); - } - - case "pdf": { - try { - const pdfUintBuffer = new Uint8Array(buffer); - const pdfDocProxy = await getDocumentProxy(pdfUintBuffer); - const { text } = await extractText(pdfDocProxy, { - mergePages: true, - }); - return text; - } catch (err: any) { - console.error( - `PDF text extraction failed: ${err?.message ?? err}`, - ); - throw new Error( - `Failed to extract text from PDF: ${err?.message ?? "unknown error"}`, - ); - } - } - - case "xlsx": - case "csv": { - const workbook = XLSX.read(buffer, { type: "buffer" }); - return workbook.SheetNames.map((name) => { - const sheet = workbook.Sheets[name]; - return `### Sheet: ${name}\n\n${XLSX.utils.sheet_to_csv(sheet!)}`; - }).join("\n\n"); - } - - case "md": - case "txt": - default: - return buffer.toString("utf-8"); - } -} diff --git a/src/functions/backend/email/email-client.ts b/src/functions/backend/email/email-client.ts deleted file mode 100644 index a0eb4e9..0000000 --- a/src/functions/backend/email/email-client.ts +++ /dev/null @@ -1,13 +0,0 @@ -import nodemailer from "nodemailer"; - -const EmailClient = nodemailer.createTransport({ - host: process.env.EMAIL_DOMAIN, - port: 465, - secure: true, - auth: { - user: process.env.EMAIL_USER, - pass: process.env.EMAIL_PASS, - }, -}); - -export default EmailClient; diff --git a/src/functions/backend/email/send-email.tsx b/src/functions/backend/email/send-email.tsx deleted file mode 100644 index a316555..0000000 --- a/src/functions/backend/email/send-email.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import { renderToString } from "react-dom/server"; -import path from "path"; -import type Mail from "nodemailer/lib/mailer"; -import type SMTPTransport from "nodemailer/lib/smtp-transport"; -import type { FC, ReactNode } from "react"; -import type { APIResponseObject } from "@moduletrace/bunext/types"; -import EmailClient from "./email-client"; - -type Params = { - options?: Mail.Options & Partial; - to: string; - content: ReactNode; - subject: string; - text: string; - title?: string; -}; - -export default async function sendEmail({ - options, - to, - content, - subject, - text, - title, -}: Params): Promise { - try { - const now = Date.now(); - const EmailRoot = ( - await import(path.join(process.cwd(), `src/email/root?t=${now}`)) - ).default as FC; - const final_component = {content}; - - const html = renderToString(final_component); - - const mail = await EmailClient.sendMail({ - from: `"${title || "SBF Mailer"}" <${process.env.EMAIL_USER}>`, - to, - subject, - text, - html, - sender: `${process.env.EMAIL_USER}`, - ...options, - }); - - return { - success: Boolean(mail.accepted?.[0]), - singleRes: mail, - }; - } catch (error: any) { - return { - success: false, - msg: error.message, - }; - } -} diff --git a/src/hooks/use-admin-crud-get.ts b/src/hooks/use-admin-crud-get.ts index 7273717..d7c6b4a 100644 --- a/src/hooks/use-admin-crud-get.ts +++ b/src/hooks/use-admin-crud-get.ts @@ -5,7 +5,7 @@ import { AppData } from "../data/app-data"; import useStatus from "../components/twui/hooks/useStatus"; import type { BUN_SQLITE_WGUI_ALL_TYPEDEFS } from "@/db/types/db"; import type { ApiReqParams, ClientAdminCrudParams, TableType } from "../types"; -import type { ServerQueryParam } from "@moduletrace/bun-sqlite/dist/types"; +import type { ServerQueryParam } from "@moduletrace/bun-sqlite/types"; import EJSON from "../utils/ejson"; type Params = Pick< diff --git a/src/pages/api/admin/crud/(tables)/media/del.ts b/src/pages/api/admin/crud/(tables)/media/del.ts index ee93bd8..11010b2 100644 --- a/src/pages/api/admin/crud/(tables)/media/del.ts +++ b/src/pages/api/admin/crud/(tables)/media/del.ts @@ -8,7 +8,7 @@ import type { } from "@/db/types/db"; import BunSQLite from "@moduletrace/bun-sqlite"; import { rmSync } from "fs"; -import type { ServerQueryParam } from "@moduletrace/bun-sqlite/dist/types"; +import type { ServerQueryParam } from "@moduletrace/bun-sqlite/types"; export default async function ( params: AdminCrudAPIParams, diff --git a/src/pages/auth/signup/index.server.ts b/src/pages/auth/signup/index.server.ts index 6d9a7cf..df68ab1 100644 --- a/src/pages/auth/signup/index.server.ts +++ b/src/pages/auth/signup/index.server.ts @@ -3,7 +3,7 @@ import type { PagePropsType } from "@/src/types"; import type { BunextPageServerFn } from "@moduletrace/bunext/types"; export const server: BunextPageServerFn = async (ctx) => { - if (ctx.props.user?.id) { + if (ctx.props?.user?.id) { return { redirect: { destination: `/admin`, diff --git a/src/types/index.ts b/src/types/index.ts index 3ecfdf6..30aab5e 100755 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,363 +1,362 @@ -import type { - BUN_SQLITE_WGUI_ALL_TYPEDEFS, - BUN_SQLITE_WGUI_CLIENTS, - BUN_SQLITE_WGUI_CLIENT_RULES, - BUN_SQLITE_WGUI_HOSTS, - BUN_SQLITE_WGUI_MEDIA, - BUN_SQLITE_WGUI_USER_TYPES, - BUN_SQLITE_WGUI_USERS, - BUN_SQLITE_WGUI_VARIABLES, - BunSQLiteTables, -} from "@/db/types/db"; -import type { SBFSusidiaries } from "../dict/subsidiaries-dict"; -import type { UserTypes } from "../dict/user-types-dict"; -import type { MediaParadigms, MediaTypes } from "../dict/media-dict"; -import type { - ClientRuleProtocols, - ClientRuleTypes, -} from "../dict/client-rules-dict"; -import type { BunextPageModuleServerReturnURLObject } from "@moduletrace/bunext/types"; -import type { - BUN_SQLITE_WGUI_USERS_JOIN, - BUN_SQLITE_WGUI_HOSTS_JOIN, - BUN_SQLITE_WGUI_CLIENTS_JOIN, -} from "./sql-joins"; -import type { ImageInputToBase64FunctionReturn } from "../components/twui/utils/form/imageInputToBase64"; -import type { ServerQueryParam } from "@moduletrace/bun-sqlite/dist/types"; -import type grabHostDirnames from "../functions/backend/setup/grab-host-dir-names"; -import type grabSystemSetupStatus from "../functions/backend/setup/grab-system-setup-status"; - -export type User = { - id: number; - first_name: string; - last_name: string; - email: string; - username?: string; - image?: string; - image_thumbnail?: string; - logged_in_status: boolean; - verification_status?: number; - date?: number; - csrf?: string; - roles?: string; -}; - -export type PagePropsType = { - user?: User | null; - user_types?: BUN_SQLITE_WGUI_USER_TYPES[] | null; - person?: BUN_SQLITE_WGUI_USERS_JOIN | null; - persons?: BUN_SQLITE_WGUI_USERS_JOIN[] | null; - host?: BUN_SQLITE_WGUI_HOSTS_JOIN | null; - hosts?: BUN_SQLITE_WGUI_HOSTS[] | null; - existing_user?: UserFormObject | null; - existing_user_full?: BUN_SQLITE_WGUI_USERS | null; - single_user?: BUN_SQLITE_WGUI_USERS_JOIN | null; - single_users?: BUN_SQLITE_WGUI_USERS_JOIN[] | null; - variables?: BUN_SQLITE_WGUI_VARIABLES[] | null; - client?: BUN_SQLITE_WGUI_CLIENTS_JOIN | null; - clients?: BUN_SQLITE_WGUI_CLIENTS_JOIN[] | null; - client_rules?: BUN_SQLITE_WGUI_CLIENT_RULES[] | null; - client_config?: string | null; - client_config_path?: string | null; - client_qr_data_uri?: string | null; - environment?: string; - envs?: { - R2_PUBLIC_DOMAIN?: string; - PAYSTACK_PUBLIC_KEY?: string; - }; - url?: BunextPageModuleServerReturnURLObject; - main_host_dir_names?: ReturnType | null; - network_interfaces?: string[] | null; - next_listen_port?: number | null; - is_main_host?: boolean | null; - main_host?: BUN_SQLITE_WGUI_HOSTS | null; - next_available_client_ip?: string | null; - is_local_ip?: boolean | null; - setup_status?: ReturnType | null; -}; - -export type AppContextObject = { - user: User | null; - appState: AppStateObject; - setAppState: React.Dispatch>; - refresh?: number; - setRefresh?: React.Dispatch>; - pageData?: any; - pageProps?: PagePropsType; - query?: PageQueryObject | null; -}; - -export type AppDataObject = {}; - -export type AppStateObject = { - data?: AppDataObject; - likes?: string[] | null; - currency?: CurrencyObjectType; - fonts?: any; - setOpenLoginModal?: React.Dispatch>; - setOpenSignUpModal?: React.Dispatch>; -}; - -export type CurrencyObjectType = { - symbol: string; - code: string; - multiplier?: number; - icon?: string; - country?: string; - countryCode?: string; -} | null; - -export type DSQL_RESPONSE = { - success: boolean; - payload?: Object[] | string | any[] | { error: string } | null; -}; - -export type DSQL_POST_QUERY_OBJECT = { - action: string; - table: string; - data?: object; - identifierColumnName?: string; - identifierValue?: string; - duplicateColumnName?: string; - duplicateColumnValue?: string; - update?: boolean; -}; - -export type AppApiRes = { - success?: boolean; - payload?: any; - result?: any; - msg?: string; -}; - -export type GithubUserObject = { - login: string; - id: 1; - node_id: string; - avatar_url: string; - gravatar_id: string; - url: string; - html_url: string; - followers_url: string; - following_url: string; - gists_url: string; - starred_url: string; - subscriptions_url: string; - organizations_url: string; - repos_url: string; - events_url: string; - received_events_url: string; - type: string; - site_admin: boolean; - name: string; - company: string; - blog: string; - location: string; - email: string; - hireable: boolean; - bio: string; - twitter_username: string; - public_repos: 2; - public_gists: 1; - followers: 20; - following: 0; - created_at: string; - updated_at: string; - private_gists: 81; - total_private_repos: 100; - owned_private_repos: 100; - disk_usage: 10000; - collaborators: 8; - two_factor_authentication: boolean; - plan: { - name: string; - space: 400; - private_repos: 20; - collaborators: 0; - }; -}; - -export type FileBase64Object = { - fileBase64: string; - fileBase64Full: string; - fileName: string; - fileSize: number; - fileType: string; -}; - -export type SubsidiaryType = (typeof SBFSusidiaries)[number]; - -export type UserType = (typeof UserTypes)[number]["value"]; - -export type LoginFormObject = { - username_or_email?: string; - password?: string; -}; - -export type ContactFormObject = { - name?: string; - email?: string; - subject?: string; - message?: string; -}; - -export type ApiReqParams< - T extends BUN_SQLITE_WGUI_ALL_TYPEDEFS = BUN_SQLITE_WGUI_ALL_TYPEDEFS, -> = { - login?: { - email?: string; - email_or_username?: string; - password?: string; - }; - current_password?: string; - new_password?: string; - confirm_password?: string; - contact?: { - name?: string; - email?: string; - subject?: string; - message?: string; - }; - image_url?: string; - sql_query?: ServerQueryParam; - sql_select_params?: any; - sql_insert_params?: any; - count?: boolean; - insert_data?: BUN_SQLITE_WGUI_ALL_TYPEDEFS[]; - update_data?: BUN_SQLITE_WGUI_ALL_TYPEDEFS; - update_on_duplicate?: boolean; - user_id?: string | number | null; - dependent_id?: string | number | null; - host_id?: string | number | null; - client_id?: string | number | null; - public_ip_address?: string | null; - interface?: string | null; - name?: string | null; - short_description?: string | null; - listen_port?: number | null; - // client_rules?: BUN_SQLITE_WGUI_CLIENT_RULES[]; - - media_base_64?: string; - media_base_64_data_url?: string; - media_paradigms?: MediaParadigmType[]; - media_paradigm?: MediaParadigmType; - media_type?: (typeof MediaTypes)[number]["value"]; - media_name?: string; - is_media_private?: boolean; - - is_media_primary?: boolean; - reauth?: boolean; - search_terms?: string[]; - amount?: number; - id?: string | number; - ids?: (string | number)[]; - paystack_payment_reference?: string; - target_user_type?: UserType; - page?: number; - /** - * Search Terms - */ - search_term_first_name?: string | string[]; - search_term_last_name?: string | string[]; - search_term_email?: string | string[]; - search_term_id?: string | string[]; - search_term_user_type?: string | string[]; - - text?: string; - return_media_text_content?: boolean; - media?: BUN_SQLITE_WGUI_MEDIA; - - ip_address?: string; - wg_ip_address?: string | null; - is_main_host?: boolean | null; - repo_url?: string; - branch?: string; -}; - -export type UserAuthReturn = { - success: boolean; - msg?: string; - user?: User | null; - user_types?: BUN_SQLITE_WGUI_USER_TYPES[] | null; -}; - -export type SQLInsertGenValueType = - | string - | number - | Float32Array - | Buffer - | null; - -export type MediaType = (typeof MediaTypes)[number]["value"]; -export type MediaParadigm = (typeof MediaParadigms)[number]["value"]; -export type ClientRuleType = (typeof ClientRuleTypes)[number]["value"]; -export type ClientRuleProtocol = (typeof ClientRuleProtocols)[number]["value"]; - -export type TableType = (typeof BunSQLiteTables)[number]; - -export type AdminCrudAPIParams = { - table: TableType; - id?: string | number; - user: User; - user_types: BUN_SQLITE_WGUI_USER_TYPES[]; - body?: ApiReqParams; - query?: ApiReqParams; - req: Request; -}; - -export type ClientAdminCrudParams< - T extends BUN_SQLITE_WGUI_ALL_TYPEDEFS = BUN_SQLITE_WGUI_ALL_TYPEDEFS, -> = { - action: "get" | "insert" | "update" | "delete"; - table: TableType; - id?: string | number; - sql_query?: ServerQueryParam; - sql_select_params?: any; - sql_insert_params?: any; - count?: boolean; - insert_data?: T[]; - update_data?: T; - update_on_duplicate?: boolean; - request_query?: ApiReqParams; - request_body?: ApiReqParams; -}; - -export type AdminFetchParams = { - url: string; - query?: ApiReqParams; - body?: ApiReqParams; - method?: "PUT" | "DELETE" | "POST" | "GET"; -}; - -export type UserFormObject = BUN_SQLITE_WGUI_USERS_JOIN; - -export type PageQueryObject = { - user_id?: string; - host_id?: string; - event_id?: string; - user_type?: UserType; -}; - -export type MediaParadigmType = (typeof MediaParadigms)[number]["value"]; - -export type AddEventFormMediaObject = BUN_SQLITE_WGUI_MEDIA & - ImageInputToBase64FunctionReturn; - -export type MediaDataType = - | Blob - | File - | NodeJS.TypedArray - | ArrayBufferLike - | string - | Bun.BlobPart[] - | Bun.Archive - | ReadableStream - | Request - | Response; - -export type AddClientFormData = { - client_name?: string; - tunnel_ip?: string; - allowed_ips?: string; - host_id: number; -}; +import type { + BUN_SQLITE_WGUI_ALL_TYPEDEFS, + BUN_SQLITE_WGUI_CLIENTS, + BUN_SQLITE_WGUI_CLIENT_RULES, + BUN_SQLITE_WGUI_HOSTS, + BUN_SQLITE_WGUI_MEDIA, + BUN_SQLITE_WGUI_USER_TYPES, + BUN_SQLITE_WGUI_USERS, + BUN_SQLITE_WGUI_VARIABLES, + BunSQLiteTables, +} from "@/db/types/db"; +import type { SBFSusidiaries } from "../dict/subsidiaries-dict"; +import type { UserTypes } from "../dict/user-types-dict"; +import type { MediaParadigms, MediaTypes } from "../dict/media-dict"; +import type { + ClientRuleProtocols, + ClientRuleTypes, +} from "../dict/client-rules-dict"; +import type { BunextPageModuleServerReturnURLObject } from "@moduletrace/bunext/types"; +import type { + BUN_SQLITE_WGUI_USERS_JOIN, + BUN_SQLITE_WGUI_HOSTS_JOIN, + BUN_SQLITE_WGUI_CLIENTS_JOIN, +} from "./sql-joins"; +import type { ImageInputToBase64FunctionReturn } from "../components/twui/utils/form/imageInputToBase64"; +import type { ServerQueryParam } from "@moduletrace/bun-sqlite/types"; +import type grabHostDirnames from "../functions/backend/setup/grab-host-dir-names"; +import type grabSystemSetupStatus from "../functions/backend/setup/grab-system-setup-status"; + +export type User = { + id: number; + first_name: string; + last_name: string; + email: string; + username?: string; + image?: string; + image_thumbnail?: string; + logged_in_status: boolean; + verification_status?: number; + date?: number; + csrf?: string; + roles?: string; +}; + +export type PagePropsType = { + user?: User | null; + user_types?: BUN_SQLITE_WGUI_USER_TYPES[] | null; + person?: BUN_SQLITE_WGUI_USERS_JOIN | null; + persons?: BUN_SQLITE_WGUI_USERS_JOIN[] | null; + host?: BUN_SQLITE_WGUI_HOSTS_JOIN | null; + hosts?: BUN_SQLITE_WGUI_HOSTS[] | null; + existing_user?: UserFormObject | null; + existing_user_full?: BUN_SQLITE_WGUI_USERS | null; + single_user?: BUN_SQLITE_WGUI_USERS_JOIN | null; + single_users?: BUN_SQLITE_WGUI_USERS_JOIN[] | null; + variables?: BUN_SQLITE_WGUI_VARIABLES[] | null; + client?: BUN_SQLITE_WGUI_CLIENTS_JOIN | null; + clients?: BUN_SQLITE_WGUI_CLIENTS_JOIN[] | null; + client_rules?: BUN_SQLITE_WGUI_CLIENT_RULES[] | null; + client_config?: string | null; + client_config_path?: string | null; + client_qr_data_uri?: string | null; + environment?: string; + envs?: { + R2_PUBLIC_DOMAIN?: string; + PAYSTACK_PUBLIC_KEY?: string; + }; + url?: BunextPageModuleServerReturnURLObject; + main_host_dir_names?: ReturnType | null; + network_interfaces?: string[] | null; + next_listen_port?: number | null; + is_main_host?: boolean | null; + main_host?: BUN_SQLITE_WGUI_HOSTS | null; + next_available_client_ip?: string | null; + is_local_ip?: boolean | null; + setup_status?: ReturnType | null; +}; + +export type AppContextObject = { + user: User | null; + appState: AppStateObject; + setAppState: React.Dispatch>; + refresh?: number; + setRefresh?: React.Dispatch>; + pageData?: any; + pageProps?: PagePropsType; + query?: PageQueryObject | null; +}; + +export type AppDataObject = {}; + +export type AppStateObject = { + data?: AppDataObject; + likes?: string[] | null; + currency?: CurrencyObjectType; + fonts?: any; + setOpenLoginModal?: React.Dispatch>; + setOpenSignUpModal?: React.Dispatch>; +}; + +export type CurrencyObjectType = { + symbol: string; + code: string; + multiplier?: number; + icon?: string; + country?: string; + countryCode?: string; +} | null; + +export type DSQL_RESPONSE = { + success: boolean; + payload?: Object[] | string | any[] | { error: string } | null; +}; + +export type DSQL_POST_QUERY_OBJECT = { + action: string; + table: string; + data?: object; + identifierColumnName?: string; + identifierValue?: string; + duplicateColumnName?: string; + duplicateColumnValue?: string; + update?: boolean; +}; + +export type AppApiRes = { + success?: boolean; + payload?: any; + result?: any; + msg?: string; +}; + +export type GithubUserObject = { + login: string; + id: 1; + node_id: string; + avatar_url: string; + gravatar_id: string; + url: string; + html_url: string; + followers_url: string; + following_url: string; + gists_url: string; + starred_url: string; + subscriptions_url: string; + organizations_url: string; + repos_url: string; + events_url: string; + received_events_url: string; + type: string; + site_admin: boolean; + name: string; + company: string; + blog: string; + location: string; + email: string; + hireable: boolean; + bio: string; + twitter_username: string; + public_repos: 2; + public_gists: 1; + followers: 20; + following: 0; + created_at: string; + updated_at: string; + private_gists: 81; + total_private_repos: 100; + owned_private_repos: 100; + disk_usage: 10000; + collaborators: 8; + two_factor_authentication: boolean; + plan: { + name: string; + space: 400; + private_repos: 20; + collaborators: 0; + }; +}; + +export type FileBase64Object = { + fileBase64: string; + fileBase64Full: string; + fileName: string; + fileSize: number; + fileType: string; +}; + +export type SubsidiaryType = (typeof SBFSusidiaries)[number]; + +export type UserType = (typeof UserTypes)[number]["value"]; + +export type LoginFormObject = { + username_or_email?: string; + password?: string; +}; + +export type ContactFormObject = { + name?: string; + email?: string; + subject?: string; + message?: string; +}; + +export type ApiReqParams< + T extends BUN_SQLITE_WGUI_ALL_TYPEDEFS = BUN_SQLITE_WGUI_ALL_TYPEDEFS, +> = { + login?: { + email?: string; + email_or_username?: string; + password?: string; + }; + current_password?: string; + new_password?: string; + confirm_password?: string; + contact?: { + name?: string; + email?: string; + subject?: string; + message?: string; + }; + image_url?: string; + sql_query?: ServerQueryParam; + sql_select_params?: any; + sql_insert_params?: any; + count?: boolean; + insert_data?: BUN_SQLITE_WGUI_ALL_TYPEDEFS[]; + update_data?: BUN_SQLITE_WGUI_ALL_TYPEDEFS; + update_on_duplicate?: boolean; + user_id?: string | number | null; + dependent_id?: string | number | null; + host_id?: string | number | null; + client_id?: string | number | null; + public_ip_address?: string | null; + interface?: string | null; + name?: string | null; + short_description?: string | null; + listen_port?: number | null; + // client_rules?: BUN_SQLITE_WGUI_CLIENT_RULES[]; + + media_base_64?: string; + media_base_64_data_url?: string; + media_paradigms?: MediaParadigmType[]; + media_paradigm?: MediaParadigmType; + media_type?: (typeof MediaTypes)[number]["value"]; + media_name?: string; + is_media_private?: boolean; + + is_media_primary?: boolean; + reauth?: boolean; + search_terms?: string[]; + amount?: number; + id?: string | number; + ids?: (string | number)[]; + paystack_payment_reference?: string; + target_user_type?: UserType; + page?: number; + /** + * Search Terms + */ + search_term_first_name?: string | string[]; + search_term_last_name?: string | string[]; + search_term_email?: string | string[]; + search_term_id?: string | string[]; + search_term_user_type?: string | string[]; + + text?: string; + media?: BUN_SQLITE_WGUI_MEDIA; + + ip_address?: string; + wg_ip_address?: string | null; + is_main_host?: boolean | null; + repo_url?: string; + branch?: string; +}; + +export type UserAuthReturn = { + success: boolean; + msg?: string; + user?: User | null; + user_types?: BUN_SQLITE_WGUI_USER_TYPES[] | null; +}; + +export type SQLInsertGenValueType = + | string + | number + | Float32Array + | Buffer + | null; + +export type MediaType = (typeof MediaTypes)[number]["value"]; +export type MediaParadigm = (typeof MediaParadigms)[number]["value"]; +export type ClientRuleType = (typeof ClientRuleTypes)[number]["value"]; +export type ClientRuleProtocol = (typeof ClientRuleProtocols)[number]["value"]; + +export type TableType = (typeof BunSQLiteTables)[number]; + +export type AdminCrudAPIParams = { + table: TableType; + id?: string | number; + user: User; + user_types: BUN_SQLITE_WGUI_USER_TYPES[]; + body?: ApiReqParams; + query?: ApiReqParams; + req: Request; +}; + +export type ClientAdminCrudParams< + T extends BUN_SQLITE_WGUI_ALL_TYPEDEFS = BUN_SQLITE_WGUI_ALL_TYPEDEFS, +> = { + action: "get" | "insert" | "update" | "delete"; + table: TableType; + id?: string | number; + sql_query?: ServerQueryParam; + sql_select_params?: any; + sql_insert_params?: any; + count?: boolean; + insert_data?: T[]; + update_data?: T; + update_on_duplicate?: boolean; + request_query?: ApiReqParams; + request_body?: ApiReqParams; +}; + +export type AdminFetchParams = { + url: string; + query?: ApiReqParams; + body?: ApiReqParams; + method?: "PUT" | "DELETE" | "POST" | "GET"; +}; + +export type UserFormObject = BUN_SQLITE_WGUI_USERS_JOIN; + +export type PageQueryObject = { + user_id?: string; + host_id?: string; + event_id?: string; + user_type?: UserType; +}; + +export type MediaParadigmType = (typeof MediaParadigms)[number]["value"]; + +export type AddEventFormMediaObject = BUN_SQLITE_WGUI_MEDIA & + ImageInputToBase64FunctionReturn; + +export type MediaDataType = + | Blob + | File + | NodeJS.TypedArray + | ArrayBufferLike + | string + | Bun.BlobPart[] + | Bun.Archive + | ReadableStream + | Request + | Response; + +export type AddClientFormData = { + client_name?: string; + tunnel_ip?: string; + allowed_ips?: string; + host_id: number; +}; diff --git a/src/utils/buffer-from-url.ts b/src/utils/buffer-from-url.ts deleted file mode 100644 index fa20b8d..0000000 --- a/src/utils/buffer-from-url.ts +++ /dev/null @@ -1,34 +0,0 @@ -export default async function bufferFromUrl( - url: string, -): Promise<{ buffer: Buffer; ext: string }> { - const res = await fetch(url); - if (!res.ok) throw new Error(`Failed to fetch ${url}: ${res.status}`); - - const contentType = res.headers.get("content-type") ?? ""; - const arrayBuffer = await res.arrayBuffer(); - const buffer = Buffer.from(arrayBuffer); - - // Derive ext from content-type first, fall back to URL path - let ext = "txt"; - if (contentType.includes("application/pdf")) ext = "pdf"; - else if ( - contentType.includes( - "application/vnd.openxmlformats-officedocument.wordprocessingml", - ) - ) - ext = "docx"; - else if ( - contentType.includes( - "application/vnd.openxmlformats-officedocument.spreadsheetml", - ) - ) - ext = "xlsx"; - else if (contentType.includes("text/csv")) ext = "csv"; - else if (contentType.includes("text/markdown")) ext = "md"; - else { - const urlPath = new URL(url).pathname; - ext = urlPath.split(".").pop()?.toLowerCase() ?? "txt"; - } - - return { buffer, ext }; -}