mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor: 🔥 Remove dead code
This commit is contained in:
parent
592f7c0ac2
commit
7b05a34cce
36 changed files with 32 additions and 1692 deletions
18
utils/api.ts
18
utils/api.ts
|
|
@ -13,17 +13,12 @@ import {
|
|||
exactly,
|
||||
} from "magic-regexp";
|
||||
import { parse } from "qs";
|
||||
import type {
|
||||
APIRouteExports,
|
||||
APIRouteMetadata,
|
||||
HttpVerb,
|
||||
RouteHandler,
|
||||
} from "server-handler";
|
||||
import type { z } from "zod";
|
||||
import { fromZodError } from "zod-validation-error";
|
||||
import type { Application } from "~database/entities/Application";
|
||||
import { getFromHeader, getFromRequest } from "~database/entities/User";
|
||||
import { getFromHeader } from "~database/entities/User";
|
||||
import type { User } from "~packages/database-interface/user";
|
||||
import type { APIRouteMetadata, HttpVerb } from "~types/api";
|
||||
|
||||
export const applyConfig = (routeMeta: APIRouteMetadata) => {
|
||||
const newMeta = routeMeta;
|
||||
|
|
@ -39,15 +34,6 @@ export const applyConfig = (routeMeta: APIRouteMetadata) => {
|
|||
return newMeta;
|
||||
};
|
||||
|
||||
export const apiRoute = <
|
||||
Metadata extends APIRouteMetadata,
|
||||
ZodSchema extends Zod.AnyZodObject,
|
||||
>(
|
||||
routeFunction: APIRouteExports["default"],
|
||||
) => {
|
||||
return routeFunction;
|
||||
};
|
||||
|
||||
export const idValidator = createRegExp(
|
||||
anyOf(digit, charIn("ABCDEF")).times(8),
|
||||
exactly("-"),
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ import { config } from "config-manager";
|
|||
import { count } from "drizzle-orm";
|
||||
import { LogLevel, type LogManager, type MultiLogManager } from "log-manager";
|
||||
import { Meilisearch } from "meilisearch";
|
||||
import type { Status } from "~database/entities/Status";
|
||||
import type { UserType } from "~database/entities/User";
|
||||
import { db } from "~drizzle/db";
|
||||
import { Notes, Users } from "~drizzle/schema";
|
||||
import type { User } from "~packages/database-interface/user";
|
||||
|
|
@ -54,18 +52,6 @@ export enum MeiliIndexType {
|
|||
Statuses = "statuses",
|
||||
}
|
||||
|
||||
export const addStausToMeilisearch = async (status: Status) => {
|
||||
if (!config.meilisearch.enabled) return;
|
||||
|
||||
await meilisearch.index(MeiliIndexType.Statuses).addDocuments([
|
||||
{
|
||||
id: status.id,
|
||||
content: status.content,
|
||||
createdAt: status.createdAt,
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
export const addUserToMeilisearch = async (user: User) => {
|
||||
if (!config.meilisearch.enabled) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
export const deepMerge = (
|
||||
target: Record<string, unknown>,
|
||||
source: Record<string, unknown>,
|
||||
) => {
|
||||
const result = { ...target, ...source };
|
||||
for (const key of Object.keys(result)) {
|
||||
result[key] =
|
||||
typeof target[key] === "object" && typeof source[key] === "object"
|
||||
? // @ts-expect-error deepMerge is recursive
|
||||
deepMerge(target[key], source[key])
|
||||
: structuredClone(result[key]);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
export const deepMergeArray = (array: Record<string, unknown>[]) =>
|
||||
array.reduce((ci, ni) => deepMerge(ci, ni), {});
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
import { fileURLToPath } from "node:url";
|
||||
|
||||
/**
|
||||
* Determines whether a module is the entry point for the running node process.
|
||||
* This works for both CommonJS and ES6 environments.
|
||||
*
|
||||
* ### CommonJS
|
||||
* ```js
|
||||
* if (moduleIsEntry(module)) {
|
||||
* console.log('WOO HOO!!!');
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* ### ES6
|
||||
* ```js
|
||||
* if (moduleIsEntry(import.meta.url)) {
|
||||
* console.log('WOO HOO!!!');
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export const moduleIsEntry = (moduleOrImportMetaUrl: NodeModule | string) => {
|
||||
if (typeof moduleOrImportMetaUrl === "string") {
|
||||
return process.argv[1] === fileURLToPath(moduleOrImportMetaUrl);
|
||||
}
|
||||
|
||||
if (typeof require !== "undefined" && "exports" in moduleOrImportMetaUrl) {
|
||||
return require.main === moduleOrImportMetaUrl;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
|
@ -59,5 +59,3 @@ export const checkIfOauthIsValid = (
|
|||
|
||||
return false;
|
||||
};
|
||||
|
||||
export const oauthCodeVerifiers: Record<string, string> = {};
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
import { exists, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
export const writeToTempDirectory = async (filename: string, data: string) => {
|
||||
const tempDir = join("/tmp/", "lysand");
|
||||
if (!(await exists(tempDir))) await mkdir(tempDir);
|
||||
|
||||
const tempFile = join(tempDir, filename);
|
||||
await writeFile(tempFile, data);
|
||||
|
||||
return tempFile;
|
||||
};
|
||||
|
||||
export const readFromTempDirectory = async (filename: string) => {
|
||||
const tempDir = join("/tmp/", "lysand");
|
||||
if (!(await exists(tempDir))) await mkdir(tempDir);
|
||||
|
||||
const tempFile = join(tempDir, filename);
|
||||
return readFile(tempFile, "utf-8");
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue