summary refs log tree commit diff
path: root/src/api/routes
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-06-16 02:39:15 +0200
committerRory& <root@rory.gay>2026-06-16 02:39:15 +0200
commit92f4099b82f9b56972aff99b74dba4c3892272cb (patch)
tree46c443c5b536d387314a86c92ef7e9ef64155c9d /src/api/routes
parentDont fetch roles if role id set is empty (diff)
downloadserver-ts-92f4099b82f9b56972aff99b74dba4c3892272cb.tar.xz
Move random string to Random class in extensions
Diffstat (limited to 'src/api/routes')
-rw-r--r--src/api/routes/auth/generate-registration-tokens.ts5
-rw-r--r--src/api/routes/channels/#channel_id/attachments.ts5
-rw-r--r--src/api/routes/channels/#channel_id/invites.ts5
-rw-r--r--src/api/routes/guilds/#guild_id/widget.json.ts5
4 files changed, 12 insertions, 8 deletions
diff --git a/src/api/routes/auth/generate-registration-tokens.ts b/src/api/routes/auth/generate-registration-tokens.ts

index 626c6f66..7b54d9ef 100644 --- a/src/api/routes/auth/generate-registration-tokens.ts +++ b/src/api/routes/auth/generate-registration-tokens.ts
@@ -17,8 +17,9 @@ */ import { Request, Response, Router } from "express"; -import { randomString, route } from "@spacebar/api"; +import { route } from "@spacebar/api"; import { ValidRegistrationToken } from "@spacebar/database"; +import { Random } from "@spacebar/extensions"; import { Config } from "@spacebar/util"; const router: Router = Router({ mergeParams: true }); @@ -48,7 +49,7 @@ router.get( for (let i = 0; i < count; i++) { const token = ValidRegistrationToken.create({ - token: randomString(length), + token: Random.getString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", length), expires_at: new Date(Date.now() + Config.get().security.defaultRegistrationTokenExpiration), }); tokens.push(token); diff --git a/src/api/routes/channels/#channel_id/attachments.ts b/src/api/routes/channels/#channel_id/attachments.ts
index e5b9e49c..8a14a135 100644 --- a/src/api/routes/channels/#channel_id/attachments.ts +++ b/src/api/routes/channels/#channel_id/attachments.ts
@@ -17,8 +17,9 @@ */ import { Request, Response, Router } from "express"; -import { randomString, route } from "@spacebar/api"; +import { route } from "@spacebar/api"; import { Channel, CloudAttachment } from "@spacebar/database"; +import { Random } from "@spacebar/extensions"; import { Config, Permissions } from "@spacebar/util"; import { UploadAttachmentRequestSchema, UploadAttachmentResponseSchema } from "@spacebar/schemas"; @@ -53,7 +54,7 @@ router.post( } const cdnUrl = Config.get().cdn.endpointPublic; - const batchId = `CLOUD_${user.id}_${randomString(128)}`; + const batchId = `CLOUD_${user.id}_${Random.getString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 128)}`; // validate IDs const seenIds: (string | undefined)[] = []; diff --git a/src/api/routes/channels/#channel_id/invites.ts b/src/api/routes/channels/#channel_id/invites.ts
index 3df4a5a8..6375a239 100644 --- a/src/api/routes/channels/#channel_id/invites.ts +++ b/src/api/routes/channels/#channel_id/invites.ts
@@ -18,10 +18,11 @@ import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server/HTTPError"; -import { randomString, route } from "@spacebar/api"; +import { route } from "@spacebar/api"; import { Channel, Guild, Invite, PublicInviteRelation, User } from "@spacebar/database"; import { InviteCreateEvent, emitEvent } from "@spacebar/util"; import { InviteCreateSchema, isTextChannel } from "@spacebar/schemas"; +import { Random } from "@spacebar/extensions"; const router: Router = Router({ mergeParams: true }); @@ -59,7 +60,7 @@ router.post( const expires_at = body.max_age == 0 || body.max_age == undefined ? undefined : new Date(body.max_age * 1000 + Date.now()); const invite = await Invite.create({ - code: randomString(), + code: Random.getString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 6), temporary: body.temporary || true, uses: 0, max_uses: body.max_uses ? Math.max(0, body.max_uses) : 0, diff --git a/src/api/routes/guilds/#guild_id/widget.json.ts b/src/api/routes/guilds/#guild_id/widget.json.ts
index 9f3ecd31..9cb4d928 100644 --- a/src/api/routes/guilds/#guild_id/widget.json.ts +++ b/src/api/routes/guilds/#guild_id/widget.json.ts
@@ -17,8 +17,9 @@ */ import { Request, Response, Router } from "express"; -import { randomString, route } from "@spacebar/api"; +import { route } from "@spacebar/api"; import { Channel, Guild, Member, Invite } from "@spacebar/database"; +import { Random } from "@spacebar/extensions"; import { Config, DiscordApiErrors, Permissions } from "@spacebar/util"; import { ChannelType, GuildWidgetJsonResponse } from "@spacebar/schemas"; @@ -93,7 +94,7 @@ async function getWidgetJsonData(guild_id: string) { const expires_at = new Date(max_age * 1000 + Date.now()); invite = await Invite.create({ - code: randomString(), + code: Random.getString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 6), temporary: false, uses: 0, max_uses: 0,