mirror of
https://github.com/spacebarchat/server.git
synced 2026-04-25 20:32:08 +00:00
snowflake-based invite generation
This commit is contained in:
@@ -21,7 +21,7 @@ export class Snowflake {
|
||||
}
|
||||
|
||||
/**
|
||||
* A Twitter snowflake, except the epoch is 2015-01-01T00:00:00.000Z
|
||||
* A Twitter-like snowflake, except the epoch is 2015-01-01T00:00:00.000Z
|
||||
* ```
|
||||
* If we have a snowflake '266241948824764416' we can represent it as binary:
|
||||
*
|
||||
@@ -83,14 +83,17 @@ export class Snowflake {
|
||||
return dec;
|
||||
}
|
||||
|
||||
static generate() {
|
||||
static generateWorkerProcess() { // worker process - returns a number
|
||||
var time = BigInt(Date.now() - Snowflake.EPOCH) << BigInt(22);
|
||||
var worker = Snowflake.workerId << 17n;
|
||||
var process = Snowflake.processId << 12n;
|
||||
var increment = Snowflake.INCREMENT++;
|
||||
return (time | worker | process | increment).toString();
|
||||
return BigInt(time | worker | process | increment);
|
||||
}
|
||||
|
||||
static generate() {
|
||||
return Snowflake.generateWorkerProcess().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* A deconstructed snowflake.
|
||||
* @typedef {Object} DeconstructedSnowflake
|
||||
|
||||
Reference in New Issue
Block a user