mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-26 12:38:07 +09:00
24 lines
601 B
TypeScript
24 lines
601 B
TypeScript
|
// AID
|
||
|
// 長さ8の[2000年1月1日からの経過ミリ秒をbase36でエンコードしたもの] + 長さ2の[ノイズ文字列]
|
||
|
|
||
|
import * as cluster from 'cluster';
|
||
|
|
||
|
const TIME2000 = 946684800000;
|
||
|
let counter = process.pid + (cluster.isMaster ? 0 : cluster.worker.id);
|
||
|
|
||
|
function getTime(time: number) {
|
||
|
time = time - TIME2000;
|
||
|
if (time < 0) time = 0;
|
||
|
|
||
|
return time.toString(36).padStart(8, '0');
|
||
|
}
|
||
|
|
||
|
function getRandom() {
|
||
|
return counter.toString(36).padStart(length, '0').substr(2);
|
||
|
}
|
||
|
|
||
|
export function genAid(date: Date): string {
|
||
|
counter++;
|
||
|
return getTime(date.getTime()) + getRandom();
|
||
|
}
|