mirror of
https://github.com/Radiquum/AniX.git
synced 2025-09-05 14:05:36 +05:00
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
export const corsHeaders = {
|
|
"Access-Control-Allow-Origin": "*",
|
|
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
|
|
"Cache-Control": "no-cache",
|
|
};
|
|
|
|
export const resHeaders = {
|
|
...corsHeaders,
|
|
"Content-Type": "application/json",
|
|
};
|
|
|
|
export function asJSON(res, object: any, status: number) {
|
|
res.status(status).type("application/json");
|
|
res.set(corsHeaders);
|
|
res.send(JSON.stringify(object));
|
|
}
|
|
|
|
export const ANIXART_UA =
|
|
"AnixartApp/8.2.1-23121216 (Android 9; SDK 28; arm64-v8a; samsung SM-G975N; en)";
|
|
export const ANIXART_API = "https://api.anixart.app";
|
|
export const ANIXART_HEADERS = {
|
|
"User-Agent": ANIXART_UA,
|
|
"Content-Type": "application/json; charset=UTF-8",
|
|
};
|
|
|
|
type LogLevel = "debug" | "info" | "warn" | "error" | "disable";
|
|
export class Log {
|
|
level: LogLevel;
|
|
levelInt = {
|
|
debug: 0,
|
|
info: 1,
|
|
warn: 2,
|
|
error: 3,
|
|
disable: 4,
|
|
};
|
|
|
|
constructor(level: LogLevel = "info") {
|
|
this.level = level;
|
|
}
|
|
|
|
getString(...args: string[]): string {
|
|
return args.toString();
|
|
}
|
|
|
|
getTime(): string {
|
|
const datetime = new Date();
|
|
return `${datetime.getHours().toString().padStart(2, "0")}:${datetime.getMinutes().toString().padStart(2, "0")}:${datetime.getSeconds().toString().padStart(2, "0")}`;
|
|
}
|
|
|
|
debug(...msg: string[]) {
|
|
if (this.levelInt[this.level] <= 0)
|
|
console.log(`[DEBUG](${this.getTime()}) -> ${this.getString(...msg)}`);
|
|
}
|
|
info(...msg: string[]) {
|
|
if (this.levelInt[this.level] <= 1)
|
|
console.log(`[INFO](${this.getTime()}) -> ${this.getString(...msg)}`);
|
|
}
|
|
warn(...msg: string[]) {
|
|
if (this.levelInt[this.level] <= 2)
|
|
console.log(`[WARN](${this.getTime()}) -> ${this.getString(...msg)}`);
|
|
}
|
|
error(...msg: string[]) {
|
|
if (this.levelInt[this.level] <= 3)
|
|
console.log(`[ERROR](${this.getTime()}) -> ${this.getString(...msg)}`);
|
|
}
|
|
|
|
debugHook(...msg: string[]) {
|
|
if (this.levelInt[this.level] <= 0)
|
|
console.log(`[DEBUG|HOOK](${this.getTime()}) -> ${this.getString(...msg)}`);
|
|
}
|
|
infoHook(...msg: string[]) {
|
|
if (this.levelInt[this.level] <= 1)
|
|
console.log(`[INFO|HOOK](${this.getTime()}) -> ${this.getString(...msg)}`);
|
|
}
|
|
warnHook(...msg: string[]) {
|
|
if (this.levelInt[this.level] <= 2)
|
|
console.log(`[WARN|HOOK](${this.getTime()}) -> ${this.getString(...msg)}`);
|
|
}
|
|
errorHook(...msg: string[]) {
|
|
if (this.levelInt[this.level] <= 3)
|
|
console.log(`[ERROR|HOOK](${this.getTime()}) -> ${this.getString(...msg)}`);
|
|
}
|
|
|
|
}
|
|
|
|
export const logger = new Log((process.env.LOG_LEVEL as LogLevel) || "info");
|