refactor: improve code structure and add better logging
All checks were successful
Code quality checks / biome (push) Successful in 10s

- Replace custom logger with @atums/echo library
- Restructure imports using # path aliases
- Add request performance tracking and better request logging
- Improve type definitions and error handling
- Add custom file serving capability
- Update biome configuration with stricter linting rules
- Add comprehensive API documentation (DOCS.md)
This commit is contained in:
creations 2025-06-13 17:45:27 -04:00
parent 82c9d72619
commit 5f0bdb885b
Signed by: creations
GPG key ID: 8F553AA4320FC711
24 changed files with 666 additions and 392 deletions

View file

@ -1,26 +0,0 @@
type Data = {
post?: Post;
posts?: Post[];
[key: string]: unknown;
};
interface DefaultPost {
directory: number;
hash: string;
id: number;
image: string;
tags: string;
}
type E621Post = {
id: number;
file: {
url: string;
};
tags: string;
};
type BooruPost = {
file_url?: string | null;
post_url?: string;
} & (DefaultPost | e621Post);

28
types/booruResponses.ts Normal file
View file

@ -0,0 +1,28 @@
type Data = {
post?: BooruPost;
posts?: BooruPost[];
[key: string]: unknown;
};
interface DefaultPost {
directory?: number;
hash?: string;
id: number;
image?: string;
tags: string | Record<string, string[]>;
}
type E621Post = {
id: number;
file: {
url: string;
};
tags: Record<string, string[]>;
};
type BooruPost = {
file_url?: string | null;
post_url?: string;
} & (DefaultPost | E621Post);
export type { Data, DefaultPost, E621Post, BooruPost };

5
types/bun.d.ts vendored
View file

@ -1,5 +0,0 @@
import type { Server } from "bun";
declare global {
type BunServer = Server;
}

10
types/bun.ts Normal file
View file

@ -0,0 +1,10 @@
type Query = Record<string, string>;
type Params = Record<string, string>;
interface ExtendedRequest extends Request {
startPerf: number;
query: Query;
params: Params;
}
export type { ExtendedRequest, Query, Params };

View file

@ -29,3 +29,5 @@ type IBooruConfig = {
functions: IBooruDefaults;
autocomplete?: string;
};
export type { Environment, IBooruDefaults, IBooruConfigMap, IBooruConfig };

9
types/logger.d.ts vendored
View file

@ -1,9 +0,0 @@
type ILogMessagePart = { value: string; color: string };
type ILogMessageParts = {
level: ILogMessagePart;
filename: ILogMessagePart;
readableTimestamp: ILogMessagePart;
message: ILogMessagePart;
[key: string]: ILogMessagePart;
};

View file

@ -1,3 +1,5 @@
import type { Server } from "bun";
type RouteDef = {
method: string;
accepts: string | null;
@ -11,10 +13,10 @@ type Params = Record<string, string>;
type RouteModule = {
handler: (
request: Request,
server: BunServer,
server: Server,
requestBody: unknown,
query: Query,
params: Params,
) => Promise<Response> | Response;
routeDef: RouteDef;
};
export type { RouteDef, Query, Params, RouteModule };