refactor: ⚰️ Remove dead code and useless files
|
Before Width: | Height: | Size: 9.1 KiB |
|
Before Width: | Height: | Size: 22 KiB |
BIN
assets/main.webp
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 34 KiB |
|
|
@ -1,10 +0,0 @@
|
||||||
// import { Queue } from "bullmq";
|
|
||||||
|
|
||||||
/* const federationQueue = new Queue("federation", {
|
|
||||||
connection: {
|
|
||||||
host: config.redis.queue.host,
|
|
||||||
port: Number(config.redis.queue.port),
|
|
||||||
password: config.redis.queue.password || undefined,
|
|
||||||
db: config.redis.queue.database || undefined,
|
|
||||||
},
|
|
||||||
}); */
|
|
||||||
|
|
@ -337,28 +337,6 @@ export const findManyUsers = async (
|
||||||
return output.map((user) => transformOutputToUserWithRelations(user));
|
return output.map((user) => transformOutputToUserWithRelations(user));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const findFirstUser = async (
|
|
||||||
query: Parameters<typeof db.query.Users.findFirst>[0],
|
|
||||||
): Promise<UserWithRelations | null> => {
|
|
||||||
const output = await db.query.Users.findFirst({
|
|
||||||
...query,
|
|
||||||
with: {
|
|
||||||
...userRelations,
|
|
||||||
...query?.with,
|
|
||||||
},
|
|
||||||
extras: {
|
|
||||||
...userExtras,
|
|
||||||
...query?.extras,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!output) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return transformOutputToUserWithRelations(output);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a WebFinger identifier to a user.
|
* Resolves a WebFinger identifier to a user.
|
||||||
* @param identifier Either a UUID or a username
|
* @param identifier Either a UUID or a username
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import { objectToInboxRequest } from "~/database/entities/federation";
|
||||||
import { addInstanceIfNotExists } from "~/database/entities/instance";
|
import { addInstanceIfNotExists } from "~/database/entities/instance";
|
||||||
import {
|
import {
|
||||||
type UserWithRelations,
|
type UserWithRelations,
|
||||||
findFirstUser,
|
|
||||||
findManyUsers,
|
findManyUsers,
|
||||||
} from "~/database/entities/user";
|
} from "~/database/entities/user";
|
||||||
import { db } from "~/drizzle/db";
|
import { db } from "~/drizzle/db";
|
||||||
|
|
@ -75,15 +74,15 @@ export class User extends BaseInterface<typeof Users, UserWithRelations> {
|
||||||
sql: SQL<unknown> | undefined,
|
sql: SQL<unknown> | undefined,
|
||||||
orderBy: SQL<unknown> | undefined = desc(Users.id),
|
orderBy: SQL<unknown> | undefined = desc(Users.id),
|
||||||
) {
|
) {
|
||||||
const found = await findFirstUser({
|
const found = await findManyUsers({
|
||||||
where: sql,
|
where: sql,
|
||||||
orderBy,
|
orderBy,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!found) {
|
if (!found[0]) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new User(found);
|
return new User(found[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async manyFromSql(
|
static async manyFromSql(
|
||||||
|
|
|
||||||
|
|
@ -226,66 +226,6 @@ export class LogManager {
|
||||||
}
|
}
|
||||||
await this.log(LogLevel.Info, "Request", string);
|
await this.log(LogLevel.Info, "Request", string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Logs a request to the output
|
|
||||||
* @param req Request to log
|
|
||||||
* @param ip IP of the request
|
|
||||||
* @param logAllDetails Whether to log all details of the request
|
|
||||||
*/
|
|
||||||
/**async logRequest(req: Request, ip?: string, logAllDetails = false) {
|
|
||||||
let string = ip ? `${ip}: ` : "";
|
|
||||||
|
|
||||||
string += `${req.method} ${req.url}`;
|
|
||||||
|
|
||||||
if (logAllDetails) {
|
|
||||||
string += "\n";
|
|
||||||
string += " [Headers]\n";
|
|
||||||
// Pretty print headers
|
|
||||||
for (const [key, value] of req.headers.entries()) {
|
|
||||||
string += ` ${key}: ${value}\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pretty print body
|
|
||||||
string += " [Body]\n";
|
|
||||||
const contentType = req.headers.get("Content-Type");
|
|
||||||
|
|
||||||
if (contentType?.includes("application/json")) {
|
|
||||||
try {
|
|
||||||
const json = await req.clone().json();
|
|
||||||
const stringified = JSON.stringify(json, null, 4)
|
|
||||||
.split("\n")
|
|
||||||
.map((line) => ` ${line}`)
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
string += `${stringified}\n`;
|
|
||||||
} catch {
|
|
||||||
string += ` [Invalid JSON] (raw: ${await req
|
|
||||||
.clone()
|
|
||||||
.text()})\n`;
|
|
||||||
}
|
|
||||||
} else if (
|
|
||||||
contentType &&
|
|
||||||
(contentType.includes("application/x-www-form-urlencoded") ||
|
|
||||||
contentType.includes("multipart/form-data"))
|
|
||||||
) {
|
|
||||||
const formData = await req.clone().formData();
|
|
||||||
for (const [key, value] of formData.entries()) {
|
|
||||||
if (value.toString().length < 300) {
|
|
||||||
string += ` ${key}: ${value.toString()}\n`;
|
|
||||||
} else {
|
|
||||||
string += ` ${key}: <${
|
|
||||||
value.toString().length
|
|
||||||
} bytes>\n`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const text = await req.text();
|
|
||||||
string += ` ${text}\n`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await this.log(LogLevel.Info, "Request", string);
|
|
||||||
} */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
import { applyConfig } from "@/api";
|
|
||||||
import { jsonResponse } from "@/response";
|
|
||||||
import type { Hono } from "hono";
|
|
||||||
import { config } from "~/packages/config-manager";
|
|
||||||
|
|
||||||
export const meta = applyConfig({
|
|
||||||
allowedMethods: ["GET"],
|
|
||||||
ratelimits: {
|
|
||||||
max: 60,
|
|
||||||
duration: 120,
|
|
||||||
},
|
|
||||||
route: "/api/_fe/config",
|
|
||||||
auth: {
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default (app: Hono) =>
|
|
||||||
app.on(meta.allowedMethods, meta.route, (_context) => {
|
|
||||||
return jsonResponse({
|
|
||||||
http: {
|
|
||||||
bind: config.http.bind,
|
|
||||||
bind_port: config.http.bind_port,
|
|
||||||
base_url: config.http.base_url,
|
|
||||||
url: config.http.bind.includes("http")
|
|
||||||
? `${config.http.bind}:${config.http.bind_port}`
|
|
||||||
: `http://${config.http.bind}:${config.http.bind_port}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
/* import type { Prisma } from "@/prisma/client";
|
|
||||||
import chalk from "chalk";
|
|
||||||
import { config } from "config-manager";
|
|
||||||
import Redis from "ioredis";
|
|
||||||
import { createPrismaRedisCache } from "prisma-redis-middleware";
|
|
||||||
|
|
||||||
const cacheRedis = config.redis.cache.enabled
|
|
||||||
? new Redis({
|
|
||||||
host: config.redis.cache.host,
|
|
||||||
port: Number(config.redis.cache.port),
|
|
||||||
password: config.redis.cache.password,
|
|
||||||
db: Number(config.redis.cache.database),
|
|
||||||
})
|
|
||||||
: null;
|
|
||||||
|
|
||||||
cacheRedis?.on("error", (e) => {
|
|
||||||
console.log(e);
|
|
||||||
});
|
|
||||||
|
|
||||||
export { cacheRedis };
|
|
||||||
|
|
||||||
export const initializeRedisCache = async () => {
|
|
||||||
if (cacheRedis) {
|
|
||||||
// Test connection
|
|
||||||
try {
|
|
||||||
await cacheRedis.ping();
|
|
||||||
} catch (e) {
|
|
||||||
console.error(
|
|
||||||
`${chalk.red("✗")} ${chalk.bold(
|
|
||||||
"Error while connecting to Redis",
|
|
||||||
)}`,
|
|
||||||
);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`${chalk.green("✓")} ${chalk.bold("Connected to Redis")}`);
|
|
||||||
|
|
||||||
const cacheMiddleware: Prisma.Middleware = createPrismaRedisCache({
|
|
||||||
storage: {
|
|
||||||
type: "redis",
|
|
||||||
options: {
|
|
||||||
client: cacheRedis,
|
|
||||||
invalidation: {
|
|
||||||
referencesTTL: 300,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cacheTime: 300,
|
|
||||||
onError: (e) => {
|
|
||||||
console.error(e);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return cacheMiddleware;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
*/
|
|
||||||