mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor: 🚨 Turn every linter rule on and fix issues (there were a LOT :3)
This commit is contained in:
parent
2e98859153
commit
a1e02d0d78
177 changed files with 1826 additions and 1248 deletions
|
|
@ -7,14 +7,14 @@ import { config } from "~/packages/config-manager";
|
|||
import { LogLevel } from "~/packages/log-manager";
|
||||
|
||||
export const bait = createMiddleware(async (context, next) => {
|
||||
const request_ip = context.env?.ip as SocketAddress | undefined | null;
|
||||
const requestIp = context.env?.ip as SocketAddress | undefined | null;
|
||||
|
||||
if (config.http.bait.enabled) {
|
||||
// Check for bait IPs
|
||||
if (request_ip?.address) {
|
||||
if (requestIp?.address) {
|
||||
for (const ip of config.http.bait.bait_ips) {
|
||||
try {
|
||||
if (matches(ip, request_ip.address)) {
|
||||
if (matches(ip, requestIp.address)) {
|
||||
const file = Bun.file(
|
||||
config.http.bait.send_file || "./beemovie.txt",
|
||||
);
|
||||
|
|
@ -23,19 +23,19 @@ export const bait = createMiddleware(async (context, next) => {
|
|||
return response(file);
|
||||
}
|
||||
await logger.log(
|
||||
LogLevel.ERROR,
|
||||
LogLevel.Error,
|
||||
"Server.Bait",
|
||||
`Bait file not found: ${config.http.bait.send_file}`,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.log(
|
||||
LogLevel.ERROR,
|
||||
LogLevel.Error,
|
||||
"Server.IPCheck",
|
||||
`Error while parsing bait IP "${ip}" `,
|
||||
);
|
||||
logger.logError(
|
||||
LogLevel.ERROR,
|
||||
LogLevel.Error,
|
||||
"Server.IPCheck",
|
||||
e as Error,
|
||||
);
|
||||
|
|
@ -61,7 +61,7 @@ export const bait = createMiddleware(async (context, next) => {
|
|||
return response(file);
|
||||
}
|
||||
await logger.log(
|
||||
LogLevel.ERROR,
|
||||
LogLevel.Error,
|
||||
"Server.Bait",
|
||||
`Bait file not found: ${config.http.bait.send_file}`,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,25 +9,25 @@ import { LogLevel } from "~/packages/log-manager";
|
|||
export const ipBans = createMiddleware(async (context, next) => {
|
||||
// Check for banned IPs
|
||||
|
||||
const request_ip = context.env?.ip as SocketAddress | undefined | null;
|
||||
const requestIp = context.env?.ip as SocketAddress | undefined | null;
|
||||
|
||||
if (!request_ip?.address) {
|
||||
if (!requestIp?.address) {
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
for (const ip of config.http.banned_ips) {
|
||||
try {
|
||||
if (matches(ip, request_ip?.address)) {
|
||||
if (matches(ip, requestIp?.address)) {
|
||||
return errorResponse("Forbidden", 403);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.log(
|
||||
LogLevel.ERROR,
|
||||
LogLevel.Error,
|
||||
"Server.IPCheck",
|
||||
`Error while parsing banned IP "${ip}" `,
|
||||
);
|
||||
logger.logError(LogLevel.ERROR, "Server.IPCheck", e as Error);
|
||||
logger.logError(LogLevel.Error, "Server.IPCheck", e as Error);
|
||||
|
||||
return errorResponse(
|
||||
`A server error occured: ${(e as Error).message}`,
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import { createMiddleware } from "hono/factory";
|
|||
import { config } from "~/packages/config-manager";
|
||||
|
||||
export const logger = createMiddleware(async (context, next) => {
|
||||
const request_ip = context.env?.ip as SocketAddress | undefined | null;
|
||||
const requestIp = context.env?.ip as SocketAddress | undefined | null;
|
||||
|
||||
if (config.logging.log_requests) {
|
||||
await dualLogger.logRequest(
|
||||
context.req.raw,
|
||||
config.logging.log_ip ? request_ip?.address : undefined,
|
||||
config.logging.log_ip ? requestIp?.address : undefined,
|
||||
config.logging.log_requests_verbose,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue