WIP: Bun changes

This commit is contained in:
Holly Stubbs 2025-01-08 14:50:10 +00:00
parent 301a3ac595
commit d612ea9668
13 changed files with 44 additions and 36 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -1,5 +1,5 @@
import LoginViewModel from "../models/account/LoginViewModel";
import RegisterViewModel from "../models/account/RegisterViewModel";
import type LoginViewModel from "../models/account/LoginViewModel";
import type RegisterViewModel from "../models/account/RegisterViewModel";
import Config from "../objects/Config";
import Session from "../objects/Session";
import UserService from "../services/UserService";

View file

@ -1,10 +1,10 @@
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { cyan } from "dyetty";
import { Console } from "hsconsole";
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import RequestCtx from "../objects/RequestCtx";
import Session from "../objects/Session";
import SessionUser from "../objects/SessionUser";
import RequestCtx from "../objects/RequestCtx";
import UserType from "../enums/UserType";
import { cyan } from "dyetty";
// prepare for ts-ignore :3
// TODO: figure out some runtime field / type checking so
@ -47,7 +47,6 @@ export default abstract class Controller {
// @ts-ignore
const controllerRequestHandler = this[method];
const requestHandler = (req:FastifyRequest, res:FastifyReply) => {
const requestStartTime = Date.now();
let session = Session.CheckValiditiy(req.cookies);
if (doAuth && session === undefined) {
return res.redirect(`/account/login?returnTo=${encodeURIComponent(req.url)}`);
@ -148,10 +147,10 @@ export default abstract class Controller {
public res: FastifyReply;
// Methods
view(view?:string | Object, model?: Object) {}
redirectToAction(action:string, controller?:string) {}
ok(message?:string) {}
badRequest(message?:string) {}
unauthorised(message?:string) {}
forbidden(message?:string) {}
view(view?:string | Object, model?: Object) { view; model; }
redirectToAction(action:string, controller?:string) { action; controller; }
ok(message?:string) { message }
badRequest(message?:string) { message }
unauthorised(message?:string) { message }
forbidden(message?:string) { message }
}

View file

@ -1,9 +1,6 @@
import DashboardViewModel from "../models/home/DashboardViewModel";
import Config from "../objects/Config";
import HashFS from "../objects/HashFS";
import UserService from "../services/UserService";
import Controller from "./Controller";
import { randomBytes } from "crypto";
import type DashboardViewModel from "../models/home/DashboardViewModel";
import UserService from "../services/UserService";
export default class HomeController extends Controller {
public async Index_Get_AllowAnonymous() {

View file

@ -15,9 +15,7 @@ import AccountController from "./controllers/AccountController";
import { magenta, blue, cyan, green, red } from "dyetty";
import ConsoleUtility from "./utilities/ConsoleUtility";
import HashFS from "./objects/HashFS";
import { existsSync, mkdirSync, rmSync } from "fs";
import FunkyArray from "funky-array";
import UserService from "./services/UserService";
import MediaService from "./services/MediaService";
import Media from "./entities/Media";
@ -98,7 +96,7 @@ fastify.addHook("onSend", (req, res, _payload, done) => {
done();
});
fastify.setNotFoundHandler(async (req, res) => {
fastify.setNotFoundHandler(async (_req, res) => {
return res.status(404).view("views/404.ejs");
});

View file

@ -1,6 +1,6 @@
import { blue } from "dyetty";
import { Console } from "hsconsole";
import { createPool, Pool, RowDataPacket } from "mysql2";
import { createPool, type Pool, type RowDataPacket } from "mysql2";
export type DBInDataType = string | number | Date | null | undefined;

View file

@ -1,13 +1,13 @@
// ! Hashed File Store (not file system!!)
import { join } from "path";
import { existsSync, mkdirSync, createWriteStream, rename, stat, writeFile, copyFile, rm, rmSync, } from "fs";
import { existsSync, mkdirSync, createWriteStream, rename, stat, writeFile, rm, rmSync, } from "fs";
import { Console } from "hsconsole";
import { yellow } from "dyetty";
import { createHash, randomBytes } from "crypto";
import FunkyArray from "funky-array";
import HashFSFileInformation from "./HashFSFileInformation";
import { BusboyFileStream } from "@fastify/busboy"
import type { BusboyFileStream } from "@fastify/busboy";
export default class HashFS {
public static STARTUP_DIR: string;

View file

@ -1,4 +1,4 @@
import { FastifyReply, FastifyRequest } from "fastify";
import { type FastifyReply, type FastifyRequest } from "fastify";
import SessionUser from "./SessionUser";
import UserType from "../enums/UserType";

View file

@ -2,7 +2,7 @@ import Config from "./Config";
import FastifyCookie from "@fastify/cookie";
import FunkyArray from "funky-array";
import SessionUser from "./SessionUser";
import { FastifyReply, FastifyRequest } from "fastify";
import { type FastifyReply } from "fastify";
import User from "../entities/User";
import { randomBytes } from "crypto";

View file

@ -17,8 +17,8 @@
"build": "tsc --build"
},
"devDependencies": {
"@types/bun": "^1.1.15",
"@types/ejs": "^3.1.5",
"@types/node": "^22.10.4",
"@vercel/ncc": "^0.38.3",
"check-outdated": "^2.12.0",
"nodemon": "^3.1.9",

View file

@ -4,7 +4,7 @@ import PasswordUtility from "../utilities/PasswordUtility";
import UserType from "../enums/UserType";
import User from "../entities/User";
import MediaRepo from "../repos/MediaRepo";
import { MultipartFile } from "@fastify/multipart"
import { type MultipartFile } from "@fastify/multipart"
import HashFS from "../objects/HashFS";
import Media from "../entities/Media";
import { randomBytes } from "crypto";

View file

@ -1,12 +1,27 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "ES2022",
"esModuleInterop": true,
"resolveJsonModule": true,
"rootDir": "./",
"outDir": "./build",
"strict": true
// Enable latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
// Some stricter flags
"noUnusedLocals": true,
"noUnusedParameters": true,
"noPropertyAccessFromIndexSignature": true
}
}

View file

@ -1,5 +1,4 @@
import { green, yellow, red, gray } from "dyetty";
import { Console } from "hsconsole";
export default abstract class ConsoleUtility {
public static StatusColor(statusCode: number) {