Compare commits
9 Commits
11.0.0-bet
...
11.0.0-bet
Author | SHA1 | Date | |
---|---|---|---|
f6f8cdbcf2 | |||
f46f53b8a3 | |||
a2fcae4383 | |||
483f043768 | |||
f8e0f4f21f | |||
9c3613e96d | |||
d9cacdc86d | |||
aa3d2deeaa | |||
e64912545a |
@ -127,28 +127,12 @@ drive:
|
|||||||
# change it according to your preferences.
|
# change it according to your preferences.
|
||||||
|
|
||||||
# Available methods:
|
# Available methods:
|
||||||
# aid1 ... Use AID for ID generation (with random 1 char)
|
# aid ... Short, Millisecond accuracy
|
||||||
# aid2 ... Use AID for ID generation (with random 2 chars)
|
# meid ... Similar to ObjectID, Millisecond accuracy
|
||||||
# aid3 ... Use AID for ID generation (with random 3 chars)
|
# ulid ... Millisecond accuracy
|
||||||
# aid4 ... Use AID for ID generation (with random 4 chars)
|
# objectid ... This is left for backward compatibility
|
||||||
# ulid ... Use ulid for ID generation
|
|
||||||
# objectid ... This is left for backward compatibility.
|
|
||||||
|
|
||||||
# AID(n) is the original ID generation method.
|
id: 'aid'
|
||||||
# The trailing n represents the number of random characters that
|
|
||||||
# will be suffixed.
|
|
||||||
# The larger n is the safer. If n is small, the possibility of
|
|
||||||
# collision at the same time increases, but there are also
|
|
||||||
# advantages such as shortening of the URL.
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
id: 'aid2'
|
|
||||||
|
|
||||||
# ┌─────────────────────┐
|
# ┌─────────────────────┐
|
||||||
#───┘ Other configuration └─────────────────────────────────────
|
#───┘ Other configuration └─────────────────────────────────────
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "misskey",
|
"name": "misskey",
|
||||||
"author": "syuilo <i@syuilo.com>",
|
"author": "syuilo <i@syuilo.com>",
|
||||||
"version": "11.0.0-beta.11",
|
"version": "11.0.0-beta.13",
|
||||||
"codename": "daybreak",
|
"codename": "daybreak",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
// AID
|
|
||||||
// 長さ8の[2000年1月1日からの経過ミリ秒をbase36でエンコードしたもの] + 長さnの[ランダムな文字列]
|
|
||||||
|
|
||||||
const CHARS = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
||||||
const TIME2000 = 946684800000;
|
|
||||||
|
|
||||||
function getTime(time: number) {
|
|
||||||
time = time - TIME2000;
|
|
||||||
if (time < 0) time = 0;
|
|
||||||
|
|
||||||
return time.toString(36);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRandom(length: number) {
|
|
||||||
let str = '';
|
|
||||||
|
|
||||||
for (let i = 0; i < length; i++) {
|
|
||||||
str += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function genAid(date: Date, rand: number): string {
|
|
||||||
return getTime(date.getTime()).padStart(8, CHARS[0]) + getRandom(rand);
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
// AID(Cheep)
|
|
||||||
// 長さ6の[2000年1月1日からの経過秒をbase36でエンコードしたもの] + 長さ3の[ランダムな文字列]
|
|
||||||
|
|
||||||
const CHARS = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
||||||
const TIME2000 = 946684800000;
|
|
||||||
|
|
||||||
function getTime(time: number) {
|
|
||||||
time = time - TIME2000;
|
|
||||||
if (time < 0) time = 0;
|
|
||||||
time = Math.floor(time / 1000);
|
|
||||||
return time.toString(36);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRandom() {
|
|
||||||
let str = '';
|
|
||||||
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
str += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function genAidc(date: Date): string {
|
|
||||||
return getTime(date.getTime()).padStart(6, CHARS[0]) + getRandom();
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
import { ulid } from 'ulid';
|
import { ulid } from 'ulid';
|
||||||
import { genAid } from './aid';
|
import { genAid } from './id/aid';
|
||||||
import { genAidc } from './aidc';
|
import { genMeid } from './id/meid';
|
||||||
import { genObjectId } from './object-id';
|
import { genObjectId } from './id/object-id';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
|
||||||
const metohd = config.id.toLowerCase();
|
const metohd = config.id.toLowerCase();
|
||||||
@ -10,11 +10,8 @@ export function genId(date?: Date): string {
|
|||||||
if (!date || (date > new Date())) date = new Date();
|
if (!date || (date > new Date())) date = new Date();
|
||||||
|
|
||||||
switch (metohd) {
|
switch (metohd) {
|
||||||
case 'aidc': return genAidc(date);
|
case 'aid': return genAid(date);
|
||||||
case 'aid1': return genAid(date, 1);
|
case 'meid': return genMeid(date);
|
||||||
case 'aid2': return genAid(date, 2);
|
|
||||||
case 'aid3': return genAid(date, 3);
|
|
||||||
case 'aid4': return genAid(date, 4);
|
|
||||||
case 'ulid': return ulid(date.getTime());
|
case 'ulid': return ulid(date.getTime());
|
||||||
case 'objectid': return genObjectId(date);
|
case 'objectid': return genObjectId(date);
|
||||||
default: throw 'unknown id generation method';
|
default: throw 'unknown id generation method';
|
||||||
|
23
src/misc/id/aid.ts
Normal file
23
src/misc/id/aid.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// 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 getNoise() {
|
||||||
|
return counter.toString(36).padStart(2, '0').slice(-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function genAid(date: Date): string {
|
||||||
|
counter++;
|
||||||
|
return getTime(date.getTime()) + getNoise();
|
||||||
|
}
|
26
src/misc/id/meid.ts
Normal file
26
src/misc/id/meid.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const CHARS = '0123456789abcdef';
|
||||||
|
|
||||||
|
function getTime(time: number) {
|
||||||
|
if (time < 0) time = 0;
|
||||||
|
if (time === 0) {
|
||||||
|
return CHARS[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
time += 0x800000000000;
|
||||||
|
|
||||||
|
return time.toString(16).padStart(12, CHARS[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getRandom() {
|
||||||
|
let str = '';
|
||||||
|
|
||||||
|
for (let i = 0; i < 12; i++) {
|
||||||
|
str += CHARS[Math.floor(Math.random() * CHARS.length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function genMeid(date: Date): string {
|
||||||
|
return 'f' + getTime(date.getTime()) + getRandom();
|
||||||
|
}
|
@ -8,7 +8,7 @@ function getTime(time: number) {
|
|||||||
|
|
||||||
time = Math.floor(time / 1000);
|
time = Math.floor(time / 1000);
|
||||||
|
|
||||||
return time.toString(16);
|
return time.toString(16).padStart(8, CHARS[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandom() {
|
function getRandom() {
|
@ -23,6 +23,14 @@ function initializeQueue(name: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderError(e: Error): any {
|
||||||
|
return {
|
||||||
|
stack: e.stack,
|
||||||
|
message: e.message,
|
||||||
|
name: e.name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const deliverQueue = initializeQueue('deliver');
|
export const deliverQueue = initializeQueue('deliver');
|
||||||
export const inboxQueue = initializeQueue('inbox');
|
export const inboxQueue = initializeQueue('inbox');
|
||||||
export const dbQueue = initializeQueue('db');
|
export const dbQueue = initializeQueue('db');
|
||||||
@ -34,16 +42,16 @@ deliverQueue
|
|||||||
.on('waiting', (jobId) => deliverLogger.debug(`waiting id=${jobId}`))
|
.on('waiting', (jobId) => deliverLogger.debug(`waiting id=${jobId}`))
|
||||||
.on('active', (job) => deliverLogger.debug(`active id=${job.id} to=${job.data.to}`))
|
.on('active', (job) => deliverLogger.debug(`active id=${job.id} to=${job.data.to}`))
|
||||||
.on('completed', (job, result) => deliverLogger.debug(`completed(${result}) id=${job.id} to=${job.data.to}`))
|
.on('completed', (job, result) => deliverLogger.debug(`completed(${result}) id=${job.id} to=${job.data.to}`))
|
||||||
.on('failed', (job, err) => deliverLogger.warn(`failed(${err}) id=${job.id} to=${job.data.to}`))
|
.on('failed', (job, err) => deliverLogger.warn(`failed(${err}) id=${job.id} to=${job.data.to}`, renderError(err)))
|
||||||
.on('error', (error) => deliverLogger.error(`error ${error}`))
|
.on('error', (error) => deliverLogger.error(`error ${error}`, renderError(error)))
|
||||||
.on('stalled', (job) => deliverLogger.warn(`stalled id=${job.id} to=${job.data.to}`));
|
.on('stalled', (job) => deliverLogger.warn(`stalled id=${job.id} to=${job.data.to}`));
|
||||||
|
|
||||||
inboxQueue
|
inboxQueue
|
||||||
.on('waiting', (jobId) => inboxLogger.debug(`waiting id=${jobId}`))
|
.on('waiting', (jobId) => inboxLogger.debug(`waiting id=${jobId}`))
|
||||||
.on('active', (job) => inboxLogger.debug(`active id=${job.id}`))
|
.on('active', (job) => inboxLogger.debug(`active id=${job.id}`))
|
||||||
.on('completed', (job, result) => inboxLogger.debug(`completed(${result}) id=${job.id}`))
|
.on('completed', (job, result) => inboxLogger.debug(`completed(${result}) id=${job.id}`))
|
||||||
.on('failed', (job, err) => inboxLogger.warn(`failed(${err}) id=${job.id} activity=${job.data.activity ? job.data.activity.id : 'none'}`))
|
.on('failed', (job, err) => inboxLogger.warn(`failed(${err}) id=${job.id} activity=${job.data.activity ? job.data.activity.id : 'none'}`, renderError(err)))
|
||||||
.on('error', (error) => inboxLogger.error(`error ${error}`))
|
.on('error', (error) => inboxLogger.error(`error ${error}`, renderError(error)))
|
||||||
.on('stalled', (job) => inboxLogger.warn(`stalled id=${job.id} activity=${job.data.activity ? job.data.activity.id : 'none'}`));
|
.on('stalled', (job) => inboxLogger.warn(`stalled id=${job.id} activity=${job.data.activity ? job.data.activity.id : 'none'}`));
|
||||||
|
|
||||||
export function deliver(user: ILocalUser, content: any, to: any) {
|
export function deliver(user: ILocalUser, content: any, to: any) {
|
||||||
|
Reference in New Issue
Block a user