From ff93a9178d05b8c60b64c7dbe29f903317e84d67 Mon Sep 17 00:00:00 2001 From: Thesourtimes Date: Sat, 1 Jan 2022 20:04:30 +0300 Subject: Organize @fosscord/api utils in directories --- api/src/util/RandomInviteID.ts | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 api/src/util/RandomInviteID.ts (limited to 'api/src/util/RandomInviteID.ts') diff --git a/api/src/util/RandomInviteID.ts b/api/src/util/RandomInviteID.ts deleted file mode 100644 index 7ea344e0..00000000 --- a/api/src/util/RandomInviteID.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Snowflake } from "@fosscord/util"; - -export function random(length = 6) { - // Declare all characters - let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - - // Pick characers randomly - let str = ""; - for (let i = 0; i < length; i++) { - str += chars.charAt(Math.floor(Math.random() * chars.length)); - } - - return str; -} - -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.concat(chars.charAt(Number(snowflake % base))); - snowflake = snowflake / base; - } - - return str.substr(3,8).split("").reverse().join(""); -} -- cgit 1.5.1