Skip to content
Snippets Groups Projects
Unverified Commit aa3d2dee authored by syuilo's avatar syuilo
Browse files

Add meid

parent e6491254
No related branches found
No related tags found
No related merge requests found
......@@ -127,18 +127,10 @@ drive:
# change it according to your preferences.
# Available methods:
# aid ... Use AID for ID generation
# ulid ... Use ulid for ID generation
# objectid ... This is left for backward compatibility.
# AID is the original ID generation method.
# ULID: Universally Unique Lexicographically Sortable Identifier.
# for more details: https://github.com/ulid/spec
# * Normally, AID should be sufficient.
# ObjectID is the method used in previous versions of Misskey.
# * Choose this if you are migrating from a previous Misskey.
# aid ... Short, Millisecond accuracy
# meid ... Similar to ObjectID, Millisecond accuracy
# ulid ... Millisecond accuracy
# objectid ... This is left for backward compatibility
id: 'aid'
......
import { ulid } from 'ulid';
import { genAid } from './id/aid';
import { genMeid } from './id/meid';
import { genObjectId } from './id/object-id';
import config from '../config';
......@@ -10,6 +11,7 @@ export function genId(date?: Date): string {
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';
......
const CHARS = '0123456789abcdef';
function getTime(time: number) {
if (time < 0) time = 0;
if (time === 0) {
return CHARS[0];
}
return time.toString(16).padStart(16, CHARS[0]);
}
function getRandom() {
let str = '';
for (let i = 0; i < 7; i++) {
str += CHARS[Math.floor(Math.random() * CHARS.length)];
}
return str;
}
export function genMeid(date: Date): string {
return 'f' + getTime(date.getTime()) + getRandom();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment