mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-24 09:49:05 +01:00
14148f6c4a
Resolve #7779
22 lines
654 B
TypeScript
22 lines
654 B
TypeScript
import { ulid } from 'ulid';
|
|
import { genAid } from './id/aid';
|
|
import { genMeid } from './id/meid';
|
|
import { genMeidg } from './id/meidg';
|
|
import { genObjectId } from './id/object-id';
|
|
import config from '@/config/index';
|
|
|
|
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 'meidg': return genMeidg(date);
|
|
case 'ulid': return ulid(date.getTime());
|
|
case 'objectid': return genObjectId(date);
|
|
default: throw new Error('unrecognized id generation method');
|
|
}
|
|
}
|