mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-13 23:25:41 +02:00
* fix: notifications-groupedのinclude/exclude typesに:groupedを指定できてしまう問題 * refactor: 通知の取得処理を Notification Service に移動 * feat: add function to parse additional part of id * fix: 通知のページネーションが正しく動かない問題 Redisにのページネーションで使用する時間及びidとRedis上のものが混同されていたので、Misskeyが生成するものに寄せました。 * pnpm run build-misskey-js-with-types * chore: XADDをretryするように * fix: notifications-groupedでxrevrangeしているのを消し忘れていた
32 lines
815 B
TypeScript
32 lines
815 B
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
// Crockford's Base32
|
|
// https://github.com/ulid/spec#encoding
|
|
import { parseBigInt32 } from '@/misc/bigint.js';
|
|
|
|
const CHARS = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
|
|
export const ulidRegExp = /^[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$/;
|
|
|
|
function parseBase32(timestamp: string) {
|
|
let time = 0;
|
|
for (let i = 0; i < timestamp.length; i++) {
|
|
time = time * 32 + CHARS.indexOf(timestamp[i]);
|
|
}
|
|
return time;
|
|
}
|
|
|
|
export function parseUlid(id: string): { date: Date; } {
|
|
return { date: new Date(parseBase32(id.slice(0, 10))) };
|
|
}
|
|
|
|
export function parseUlidFull(id: string): { date: number; additional: bigint; } {
|
|
return {
|
|
date: parseBase32(id.slice(0, 10)),
|
|
additional: parseBigInt32(id.slice(10, 26)),
|
|
};
|
|
}
|