mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-29 14:46:43 -06:00
19 lines
555 B
TypeScript
19 lines
555 B
TypeScript
import { ulid } from 'ulid';
|
|
import { genAid } from './id/aid';
|
|
import { genMeid } from './id/meid';
|
|
import { genObjectId } from './id/object-id';
|
|
import config from '../config';
|
|
|
|
const metohd = config.id.toLowerCase();
|
|
|
|
export function genId(date?: Date): string {
|
|
if (!date || (date > new Date())) date = new Date();
|
|
|
|
switch (metohd) {
|
|
case 'aid': return genAid(date);
|
|
case 'meid': return genMeid(date);
|
|
case 'ulid': return ulid(date.getTime());
|
|
case 'objectid': return genObjectId(date);
|
|
default: throw 'unknown id generation method';
|
|
}
|
|
}
|