From 9b67dabea8df4a4a1bc341e532690c954057ec02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkin=20Alp=20G=C3=BCney?= Date: Tue, 30 Nov 2021 20:33:29 +0300 Subject: [PATCH] Fix the type errors Forgot that you cannot mix and match bigint and float --- api/src/util/RandomInviteID.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/api/src/util/RandomInviteID.ts b/api/src/util/RandomInviteID.ts index 45450b0d..30ba3252 100644 --- a/api/src/util/RandomInviteID.ts +++ b/api/src/util/RandomInviteID.ts @@ -16,16 +16,17 @@ export function random(length = 6) { export function snowflakeBasedInvite() { // Declare all characters let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - + let base = BigInt(chars.length); let snowflake = Snowflake.generateWorkerProcess(); - + // snowflakes hold ~10.75 characters worth of entropy; // safe to generate a 8-char invite out of them let str = ""; for (let i=0; i < 10; i++) { - str += chars.charAt((snowflake % chars.length)); - snowflake /= chars.length; + + str += chars.charAt(snowflake % base); + snowflake = snowflake / base; } - return str.substr(3,8).reverse(); // little-endianise for entropy + return str.substr(3,8).split("").reverse().join(""); }