mirror of
https://iceshrimp.dev/Crimekillz/jointrashposs.git
synced 2024-11-22 17:03:50 +01:00
Refactor AID generation logic
This commit is contained in:
parent
1dd2fd95bd
commit
c25aa1b374
@ -5,18 +5,16 @@
|
|||||||
|
|
||||||
// AID
|
// AID
|
||||||
// 長さ8の[2000年1月1日からの経過ミリ秒をbase36でエンコードしたもの] + 長さ2の[ノイズ文字列]
|
// 長さ8の[2000年1月1日からの経過ミリ秒をbase36でエンコードしたもの] + 長さ2の[ノイズ文字列]
|
||||||
|
import { customAlphabet } from 'nanoid';
|
||||||
|
|
||||||
export const aidRegExp = /^[0-9a-z]{10}$/;
|
export const aidRegExp = /^[0-9a-z]{10}$/;
|
||||||
|
|
||||||
|
const rand = customAlphabet('0123456789', 5);
|
||||||
|
|
||||||
const TIME2000 = 946684800000;
|
const TIME2000 = 946684800000;
|
||||||
let counter: number;
|
let counter: number;
|
||||||
|
|
||||||
if (process.client) {
|
counter = parseInt(rand(), 10);
|
||||||
const arr = window.crypto.getRandomValues(new Uint16Array(2));
|
|
||||||
counter = parseInt(arr[0].toString());
|
|
||||||
} else {
|
|
||||||
const crypto = await import('crypto');
|
|
||||||
counter = crypto.randomBytes(2).readUInt16LE(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTime(time: number): string {
|
function getTime(time: number): string {
|
||||||
time = time - TIME2000;
|
time = time - TIME2000;
|
||||||
|
Loading…
Reference in New Issue
Block a user