summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-06-12 16:27:38 +0200
committerRory& <root@rory.gay>2026-06-12 17:58:18 +0200
commit03ecae4348182885b8aa06d2b42c2e7da88923b2 (patch)
treed6101462a387ff6523fce39fa0bdb58789a797ef /src/api
parentMove migrations to database (diff)
downloadserver-ts-03ecae4348182885b8aa06d2b42c2e7da88923b2.tar.xz
Move more extensions to extensions
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/applications/index.ts3
-rw-r--r--src/api/routes/auth/register.ts3
-rw-r--r--src/api/routes/channels/#channel_id/webhooks.ts3
-rw-r--r--src/api/routes/guilds/#guild_id/templates.ts3
-rw-r--r--src/api/routes/users/#user_id/delete.ts7
-rw-r--r--src/api/routes/users/@me/mentions.ts3
-rw-r--r--src/api/util/handlers/Instance.ts4
-rw-r--r--src/api/util/handlers/Message.ts3
-rw-r--r--src/api/util/index.ts1
-rw-r--r--src/api/util/utility/EmbedHandlers.ts4
-rw-r--r--src/api/util/utility/String.ts38
11 files changed, 19 insertions, 53 deletions
diff --git a/src/api/routes/applications/index.ts b/src/api/routes/applications/index.ts

index 820716b5..894f9331 100644 --- a/src/api/routes/applications/index.ts +++ b/src/api/routes/applications/index.ts
@@ -19,8 +19,9 @@ import { Request, Response, Router } from "express"; import { route } from "@spacebar/api"; import { Application } from "@spacebar/database"; -import { Config, createAppBotUser, trimSpecial } from "@spacebar/util"; +import { Config, createAppBotUser } from "@spacebar/util"; import { ApplicationCreateSchema } from "@spacebar/schemas"; +import { trimSpecial } from "@spacebar/extensions"; const router: Router = Router({ mergeParams: true }); diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts
index 13721c04..379d2775 100644 --- a/src/api/routes/auth/register.ts +++ b/src/api/routes/auth/register.ts
@@ -22,9 +22,10 @@ import { HTTPError } from "lambert-server/HTTPError"; import { MoreThan } from "typeorm"; import { route, verifyCaptcha } from "@spacebar/api"; import { Invite, User, ValidRegistrationToken } from "@spacebar/database"; -import { Config, FieldErrors, generateToken, IpDataClient, AbuseIpDbClient, TimeSpan, Stopwatch } from "@spacebar/util"; +import { Config, FieldErrors, generateToken, IpDataClient, AbuseIpDbClient } from "@spacebar/util"; import { RegisterSchema } from "@spacebar/schemas"; import { BcryptWorkerPool } from "../../../util/util/workers/bcrypt/BcryptWorkerPool"; +import { Stopwatch, TimeSpan } from "@spacebar/extensions"; const router: Router = Router({ mergeParams: true }); diff --git a/src/api/routes/channels/#channel_id/webhooks.ts b/src/api/routes/channels/#channel_id/webhooks.ts
index b3efb187..0dac7574 100644 --- a/src/api/routes/channels/#channel_id/webhooks.ts +++ b/src/api/routes/channels/#channel_id/webhooks.ts
@@ -21,8 +21,9 @@ import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server/HTTPError"; import { route } from "@spacebar/api"; import { Application, Channel, User, Webhook } from "@spacebar/database"; -import { Config, DiscordApiErrors, handleFile, trimSpecial, ValidateName } from "@spacebar/util"; +import { Config, DiscordApiErrors, handleFile, ValidateName } from "@spacebar/util"; import { isTextChannel, WebhookCreateSchema, WebhookType } from "@spacebar/schemas"; +import { trimSpecial } from "@spacebar/extensions"; const router: Router = Router({ mergeParams: true }); diff --git a/src/api/routes/guilds/#guild_id/templates.ts b/src/api/routes/guilds/#guild_id/templates.ts
index 9942fef1..f2782bb8 100644 --- a/src/api/routes/guilds/#guild_id/templates.ts +++ b/src/api/routes/guilds/#guild_id/templates.ts
@@ -18,8 +18,9 @@ import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server/HTTPError"; -import { generateCode, route } from "@spacebar/api"; +import { route } from "@spacebar/api"; import { Guild, Template } from "@spacebar/database"; +import { generateCode } from "@spacebar/extensions"; const router: Router = Router({ mergeParams: true }); diff --git a/src/api/routes/users/#user_id/delete.ts b/src/api/routes/users/#user_id/delete.ts
index 49be55e2..9b12c7bb 100644 --- a/src/api/routes/users/#user_id/delete.ts +++ b/src/api/routes/users/#user_id/delete.ts
@@ -16,12 +16,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import { Request, Response, Router } from "express"; +import { Not } from "typeorm"; import { route } from "@spacebar/api"; import { Channel, Emoji, Guild, InstanceBan, Member, Recipient, Sticker, User, UserSettingsProtos } from "@spacebar/database"; -import { ChannelDeleteEvent, ChannelRecipientRemoveEvent, emitEvent, Stopwatch, UserDeleteEvent } from "@spacebar/util"; -import { Request, Response, Router } from "express"; +import { ChannelDeleteEvent, ChannelRecipientRemoveEvent, emitEvent, UserDeleteEvent } from "@spacebar/util"; import { ChannelType, InstanceUserDeleteSchema, PrivateUserProjection } from "@spacebar/schemas"; -import { Not } from "typeorm"; +import { Stopwatch } from "@spacebar/extensions"; const router = Router({ mergeParams: true }); diff --git a/src/api/routes/users/@me/mentions.ts b/src/api/routes/users/@me/mentions.ts
index e0908458..88d7ebb0 100644 --- a/src/api/routes/users/@me/mentions.ts +++ b/src/api/routes/users/@me/mentions.ts
@@ -20,7 +20,8 @@ import { Request, Response, Router } from "express"; import { In, LessThan, FindOptionsWhere } from "typeorm"; import { route } from "@spacebar/api"; import { Message, Member, Channel, Attachment } from "@spacebar/database"; -import { Snowflake, Permissions, NewUrlUserSignatureData, Stopwatch } from "@spacebar/util"; +import { Snowflake, Permissions, NewUrlUserSignatureData } from "@spacebar/util"; +import { Stopwatch } from "@spacebar/extensions"; const router: Router = Router({ mergeParams: true }); diff --git a/src/api/util/handlers/Instance.ts b/src/api/util/handlers/Instance.ts
index 52d241aa..64c4ac96 100644 --- a/src/api/util/handlers/Instance.ts +++ b/src/api/util/handlers/Instance.ts
@@ -16,9 +16,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { Session } from "@spacebar/database"; -import { TimeSpan } from "@spacebar/util"; import { setInterval } from "node:timers"; +import { Session } from "@spacebar/database"; +import { TimeSpan } from "@spacebar/extensions"; export async function initInstance() { // TODO: clean up database and delete tombstone data diff --git a/src/api/util/handlers/Message.ts b/src/api/util/handlers/Message.ts
index 65d41e43..d0176693 100644 --- a/src/api/util/handlers/Message.ts +++ b/src/api/util/handlers/Message.ts
@@ -20,7 +20,7 @@ import { HTTPError } from "lambert-server/HTTPError"; import { Equal, In, Or } from "typeorm"; import { fillMessageUrlEmbeds, randomString } from "@spacebar/api"; import { getDatabase, Application, Attachment, Channel, CloudAttachment, Guild, Member, Message, ReadState, Role, Session, Sticker, User, Webhook } from "@spacebar/database"; -import { mathLogBase, arrayDistributeSequentially } from "@spacebar/extensions"; +import { mathLogBase, arrayDistributeSequentially, Stopwatch } from "@spacebar/extensions"; import { Config, DiscordApiErrors, @@ -36,7 +36,6 @@ import { Permissions, ROLE_MENTION, Snowflake, - Stopwatch, TraceNode, TraceRoot, TraceSubTree, diff --git a/src/api/util/index.ts b/src/api/util/index.ts
index cb26d4f5..c7cbc535 100644 --- a/src/api/util/index.ts +++ b/src/api/util/index.ts
@@ -22,7 +22,6 @@ export * from "./handlers/Message"; export * from "./utility/passwordStrength"; export * from "./utility/RandomInviteID"; export * from "./handlers/route"; -export * from "./utility/String"; export * from "./handlers/Voice"; export * from "./utility/captcha"; export * from "./utility/EmbedHandlers"; diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts
index c18e4f79..9aedce11 100644 --- a/src/api/util/utility/EmbedHandlers.ts +++ b/src/api/util/utility/EmbedHandlers.ts
@@ -22,8 +22,8 @@ import { yellow } from "picocolors"; import probe from "probe-image-size"; import { FindOptionsWhere, In } from "typeorm"; import { EmbedCache, Message } from "@spacebar/database"; -import { sleep, arrayDistinctBy, arrayGroupBy } from "@spacebar/extensions"; -import { Config, emitEvent, MessageUpdateEvent, normalizeUrl, OrmUtils } from "@spacebar/util"; +import { sleep, arrayDistinctBy, arrayGroupBy, normalizeUrl } from "@spacebar/extensions"; +import { Config, emitEvent, MessageUpdateEvent, OrmUtils } from "@spacebar/util"; import { Embed, EmbedImage, EmbedType } from "@spacebar/schemas"; export function getDefaultFetchOptions(): RequestInit { diff --git a/src/api/util/utility/String.ts b/src/api/util/utility/String.ts deleted file mode 100644
index e33613a3..00000000 --- a/src/api/util/utility/String.ts +++ /dev/null
@@ -1,38 +0,0 @@ -/* - Spacebar: A FOSS re-implementation and extension of the Discord.com backend. - Copyright (C) 2023 Spacebar and Spacebar Contributors - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <https://www.gnu.org/licenses/>. -*/ - -import { Request } from "express"; -import { ntob } from "./Base64"; -import { FieldErrors, Random } from "@spacebar/util"; - -export function checkLength(str: string, min: number, max: number, key: string, req: Request) { - if (str.length < min || str.length > max) { - throw FieldErrors({ - [key]: { - code: "BASE_TYPE_BAD_LENGTH", - message: req.t("common:field.BASE_TYPE_BAD_LENGTH", { - length: `${min} - ${max}`, - }), - }, - }); - } -} - -export function generateCode() { - return ntob(Date.now() + Random.nextInt(0, 10000)); -}