diff --git a/src/api/util/utility/RandomInviteID.ts b/src/api/util/utility/RandomInviteID.ts index bd50ed928..3850df544 100644 --- a/src/api/util/utility/RandomInviteID.ts +++ b/src/api/util/utility/RandomInviteID.ts @@ -24,8 +24,7 @@ import crypto from "crypto"; export function randomString(length = 6) { // Declare all characters - const chars = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; // Pick characers randomly let str = ""; @@ -38,8 +37,7 @@ export function randomString(length = 6) { export function snowflakeBasedInvite() { // Declare all characters - const chars = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; const base = BigInt(chars.length); let snowflake = Snowflake.generateWorkerProcess(); @@ -53,3 +51,14 @@ export function snowflakeBasedInvite() { return str.substr(3, 8).split("").reverse().join(""); } + +export function randomUpperString(length: number = 10) { + const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + let result = ""; + for (let i = 0; i < length; i++) { + result += chars.charAt(Math.floor(Math.random() * chars.length)); + } + + return result; +} diff --git a/src/util/entities/Session.ts b/src/util/entities/Session.ts index 1f0e52126..093933b85 100644 --- a/src/util/entities/Session.ts +++ b/src/util/entities/Session.ts @@ -22,7 +22,7 @@ import { ClientSession, Column, CreateDateColumn, Entity, Index, JoinColumn, Man import { ClientStatus, Status } from "../interfaces/Status"; import { Activity } from "../interfaces/Activity"; import crypto from "crypto"; -import { randomString, randomUpperString } from "@spacebar/api*"; +import { randomUpperString } from "@spacebar/api"; //TODO we need to remove all sessions on server start because if the server crashes without closing websockets it won't delete them