refactor (backend-rs): rewrite id generator
Co-authored-by: sup39 <dev@sup39.dev>
This commit is contained in:
parent
186919aac3
commit
f60ff2eaf4
77 changed files with 115 additions and 137 deletions
|
@ -310,7 +310,7 @@ if (!nativeBinding) {
|
|||
throw new Error(`Failed to load native binding`)
|
||||
}
|
||||
|
||||
const { AntennaSrcEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, nativeRandomStr, IdConvertType, convertId, nativeGetTimestamp, nativeCreateId, nativeInitIdGenerator } = nativeBinding
|
||||
const { AntennaSrcEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, secureRndstr, IdConvertType, convertId, getTimestamp, genId, initIdGenerator } = nativeBinding
|
||||
|
||||
module.exports.AntennaSrcEnum = AntennaSrcEnum
|
||||
module.exports.MutedNoteReasonEnum = MutedNoteReasonEnum
|
||||
|
@ -322,9 +322,9 @@ module.exports.RelayStatusEnum = RelayStatusEnum
|
|||
module.exports.UserEmojimodpermEnum = UserEmojimodpermEnum
|
||||
module.exports.UserProfileFfvisibilityEnum = UserProfileFfvisibilityEnum
|
||||
module.exports.UserProfileMutingnotificationtypesEnum = UserProfileMutingnotificationtypesEnum
|
||||
module.exports.nativeRandomStr = nativeRandomStr
|
||||
module.exports.secureRndstr = secureRndstr
|
||||
module.exports.IdConvertType = IdConvertType
|
||||
module.exports.convertId = convertId
|
||||
module.exports.nativeGetTimestamp = nativeGetTimestamp
|
||||
module.exports.nativeCreateId = nativeCreateId
|
||||
module.exports.nativeInitIdGenerator = nativeInitIdGenerator
|
||||
module.exports.getTimestamp = getTimestamp
|
||||
module.exports.genId = genId
|
||||
module.exports.initIdGenerator = initIdGenerator
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use basen::BASE36;
|
||||
use cfg_if::cfg_if;
|
||||
use chrono::Utc;
|
||||
use chrono::NaiveDateTime;
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::cmp;
|
||||
|
||||
|
@ -33,20 +33,14 @@ pub fn init_id(length: u16, fingerprint: &str) {
|
|||
|
||||
/// Returns Cuid2 with the length specified by [init_id]. Must be called after
|
||||
/// [init_id], otherwise returns [ErrorUninitialized].
|
||||
/// The current timestamp via [chrono::Utc] is used if `date_num` is `0`.
|
||||
pub fn create_id(date_num: i64) -> Result<String, ErrorUninitialized> {
|
||||
pub fn create_id(datetime: &NaiveDateTime) -> Result<String, ErrorUninitialized> {
|
||||
match GENERATOR.get() {
|
||||
None => Err(ErrorUninitialized),
|
||||
Some(gen) => {
|
||||
let date_num = if date_num > 0 {
|
||||
date_num
|
||||
} else {
|
||||
Utc::now().timestamp_millis()
|
||||
};
|
||||
let time = cmp::max(date_num - TIME_2000, 0);
|
||||
let date_num = cmp::max(0, datetime.and_utc().timestamp_millis() - TIME_2000) as u64;
|
||||
Ok(format!(
|
||||
"{:0>8}{}",
|
||||
BASE36.encode_var_len(&(time as u64)),
|
||||
BASE36.encode_var_len(&date_num),
|
||||
gen.create_id()
|
||||
))
|
||||
}
|
||||
|
@ -64,20 +58,26 @@ pub fn get_timestamp(id: &str) -> i64 {
|
|||
cfg_if! {
|
||||
if #[cfg(feature = "napi")] {
|
||||
use napi_derive::napi;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
/// Calls [init_id] inside. Must be called before [native_create_id].
|
||||
#[napi]
|
||||
#[napi(js_name = "initIdGenerator")]
|
||||
pub fn native_init_id_generator(length: u16, fingerprint: String) {
|
||||
init_id(length, &fingerprint);
|
||||
}
|
||||
|
||||
/// Generates
|
||||
/// The generated ID results in the form of `[8 chars timestamp] + [cuid2]`.
|
||||
/// The minimum and maximum lengths are 16 and 24, respectively.
|
||||
/// With the length of 16, namely 8 for cuid2, roughly 1427399 IDs are needed
|
||||
/// in the same millisecond to reach 50% chance of collision.
|
||||
///
|
||||
/// Ref: https://github.com/paralleldrive/cuid2#parameterized-length
|
||||
#[napi]
|
||||
pub fn native_create_id(date_num: i64) -> String {
|
||||
create_id(date_num).unwrap()
|
||||
pub fn gen_id(date: Option<DateTime<Utc>>) -> String {
|
||||
create_id(&date.unwrap_or_else(|| Utc::now()).naive_utc()).unwrap()
|
||||
}
|
||||
|
||||
#[napi]
|
||||
#[napi(js_name = "getTimestamp")]
|
||||
pub fn native_get_timestamp(id: String) -> i64 {
|
||||
get_timestamp(&id)
|
||||
}
|
||||
|
@ -92,18 +92,18 @@ mod unit_test {
|
|||
use std::thread;
|
||||
|
||||
#[test]
|
||||
fn can_create_and_decode() {
|
||||
assert_eq!(id::create_id(0), Err(id::ErrorUninitialized));
|
||||
fn can_create_and_decode_id() {
|
||||
let now = Utc::now().naive_utc();
|
||||
assert_eq!(id::create_id(&now), Err(id::ErrorUninitialized));
|
||||
id::init_id(16, "");
|
||||
assert_eq!(id::create_id(0).unwrap().len(), 16);
|
||||
assert_ne!(id::create_id(0).unwrap(), id::create_id(0).unwrap());
|
||||
let id1 = thread::spawn(|| id::create_id(0).unwrap());
|
||||
let id2 = thread::spawn(|| id::create_id(0).unwrap());
|
||||
assert_eq!(id::create_id(&now).unwrap().len(), 16);
|
||||
assert_ne!(id::create_id(&now).unwrap(), id::create_id(&now).unwrap());
|
||||
let id1 = thread::spawn(move || id::create_id(&now).unwrap());
|
||||
let id2 = thread::spawn(move || id::create_id(&now).unwrap());
|
||||
assert_ne!(id1.join().unwrap(), id2.join().unwrap());
|
||||
|
||||
let now = Utc::now().timestamp_millis();
|
||||
let test_id = id::create_id(now).unwrap();
|
||||
let test_id = id::create_id(&now).unwrap();
|
||||
let timestamp = id::get_timestamp(&test_id);
|
||||
assert_eq!(now, timestamp);
|
||||
assert_eq!(now.and_utc().timestamp_millis(), timestamp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,9 @@ pub fn gen_string(length: u16) -> String {
|
|||
}
|
||||
|
||||
#[cfg(feature = "napi")]
|
||||
#[napi_derive::napi]
|
||||
pub fn native_random_str(length: u16) -> String {
|
||||
gen_string(length)
|
||||
#[napi_derive::napi(js_name = "secureRndstr")]
|
||||
pub fn native_random_str(length: Option<u16>) -> String {
|
||||
gen_string(length.unwrap_or(32))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
import cluster from "node:cluster";
|
||||
import config from "@/config/index.js";
|
||||
import { initDb } from "@/db/postgre.js";
|
||||
import { initIdGenerator } from "backend-rs";
|
||||
import os from "node:os";
|
||||
|
||||
/**
|
||||
* Init worker process
|
||||
*/
|
||||
export async function workerMain() {
|
||||
const length = Math.min(Math.max(config.cuid?.length ?? 16, 16), 24);
|
||||
const fingerprint = config.cuid?.fingerprint ?? "";
|
||||
initIdGenerator(length, fingerprint);
|
||||
|
||||
await initDb();
|
||||
|
||||
if (!process.env.mode || process.env.mode === "web") {
|
||||
|
|
|
@ -1,26 +1,6 @@
|
|||
import config from "@/config/index.js";
|
||||
import {
|
||||
nativeCreateId,
|
||||
nativeInitIdGenerator,
|
||||
nativeGetTimestamp,
|
||||
} from "backend-rs";
|
||||
import { initIdGenerator } from "backend-rs";
|
||||
|
||||
const length = Math.min(Math.max(config.cuid?.length ?? 16, 16), 24);
|
||||
const fingerprint = config.cuid?.fingerprint ?? "";
|
||||
nativeInitIdGenerator(length, fingerprint);
|
||||
|
||||
/**
|
||||
* The generated ID results in the form of `[8 chars timestamp] + [cuid2]`.
|
||||
* The minimum and maximum lengths are 16 and 24, respectively.
|
||||
* With the length of 16, namely 8 for cuid2, roughly 1427399 IDs are needed
|
||||
* in the same millisecond to reach 50% chance of collision.
|
||||
*
|
||||
* Ref: https://github.com/paralleldrive/cuid2#parameterized-length
|
||||
*/
|
||||
export function genId(date?: Date): string {
|
||||
return nativeCreateId(date?.getTime() ?? Date.now());
|
||||
}
|
||||
|
||||
export function getTimestamp(id: string): number {
|
||||
return nativeGetTimestamp(id);
|
||||
}
|
||||
initIdGenerator(length, fingerprint);
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
import { nativeRandomStr } from "backend-rs";
|
||||
|
||||
export function secureRndstr(length = 32, _ = true): string {
|
||||
return nativeRandomStr(length);
|
||||
}
|
|
@ -8,7 +8,7 @@ import { downloadUrl } from "@/misc/download-url.js";
|
|||
import { DriveFiles, Emojis } from "@/models/index.js";
|
||||
import type { DbUserImportJobData } from "@/queue/types.js";
|
||||
import { addFile } from "@/services/drive/add-file.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { db } from "@/db/postgre.js";
|
||||
import probeImageSize from "probe-image-size";
|
||||
import * as path from "path";
|
||||
|
|
|
@ -9,7 +9,7 @@ import type Bull from "bull";
|
|||
import { createImportCkPostJob } from "@/queue/index.js";
|
||||
import { Notes, NoteEdits } from "@/models/index.js";
|
||||
import type { Note } from "@/models/entities/note.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
const logger = queueLogger.createSubLogger("import-firefish-post");
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import { uploadFromUrl } from "@/services/drive/upload-from-url.js";
|
|||
import type { DriveFile } from "@/models/entities/drive-file.js";
|
||||
import { Notes, NoteEdits } from "@/models/index.js";
|
||||
import type { Note } from "@/models/entities/note.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
const logger = queueLogger.createSubLogger("import-masto-post");
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import { isSelfHost, toPuny } from "@/misc/convert-host.js";
|
|||
import { Users, DriveFiles, Mutings } from "@/models/index.js";
|
||||
import type { DbUserImportJobData } from "@/queue/types.js";
|
||||
import type { User } from "@/models/entities/user.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { IsNull } from "typeorm";
|
||||
import { inspect } from "node:util";
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
UserLists,
|
||||
UserListJoinings,
|
||||
} from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { DbUserImportJobData } from "@/queue/types.js";
|
||||
import { IsNull } from "typeorm";
|
||||
import { inspect } from "node:util";
|
||||
|
|
|
@ -4,7 +4,7 @@ import type { IFlag } from "../../type.js";
|
|||
import { getApIds } from "../../type.js";
|
||||
import { AbuseUserReports, Users } from "@/models/index.js";
|
||||
import { In } from "typeorm";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export default async (
|
||||
actor: CacheableRemoteUser,
|
||||
|
|
|
@ -33,7 +33,7 @@ import {
|
|||
getApType,
|
||||
} from "../type.js";
|
||||
import type { Emoji } from "@/models/entities/emoji.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { getApLock } from "@/misc/app-lock.js";
|
||||
import { createMessage } from "@/services/messages/create.js";
|
||||
import { parseAudience } from "../audience.js";
|
||||
|
|
|
@ -16,7 +16,7 @@ import type { IRemoteUser, CacheableUser } from "@/models/entities/user.js";
|
|||
import { User } from "@/models/entities/user.js";
|
||||
import type { Emoji } from "@/models/entities/emoji.js";
|
||||
import { UserNotePining } from "@/models/entities/user-note-pining.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { UserPublickey } from "@/models/entities/user-publickey.js";
|
||||
import { isDuplicateKeyValueError } from "@/misc/is-duplicate-key-value-error.js";
|
||||
import { isSameOrigin, toPuny } from "@/misc/convert-host.js";
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
import { secureRndstr } from "@/misc/secure-rndstr.js";
|
||||
import { secureRndstr } from "backend-rs";
|
||||
|
||||
export default () => secureRndstr(16, true);
|
||||
export default () => secureRndstr(16);
|
||||
|
|
|
@ -3,7 +3,7 @@ import type Koa from "koa";
|
|||
import config from "@/config/index.js";
|
||||
import type { ILocalUser } from "@/models/entities/user.js";
|
||||
import { Signins } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { publishMainStream } from "@/services/stream.js";
|
||||
|
||||
export default function (ctx: Koa.Context, user: ILocalUser, redirect = false) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { User } from "@/models/entities/user.js";
|
|||
import { Users, UsedUsernames } from "@/models/index.js";
|
||||
import { UserProfile } from "@/models/entities/user-profile.js";
|
||||
import { IsNull } from "typeorm";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { toPunyNullable } from "@/misc/convert-host.js";
|
||||
import { UserKeypair } from "@/models/entities/user-keypair.js";
|
||||
import { UsedUsername } from "@/models/entities/used-username.js";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { Ads } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { Announcements } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { Emojis, DriveFiles } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { insertModerationLog } from "@/services/insert-moderation-log.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import rndstr from "rndstr";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { Emojis } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import type { DriveFile } from "@/models/entities/drive-file.js";
|
||||
import { uploadFromUrl } from "@/services/drive/upload-from-url.js";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import rndstr from "rndstr";
|
||||
import define from "@/server/api/define.js";
|
||||
import { RegistrationTickets } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["admin"],
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { Antennas, UserLists, UserGroupJoinings } from "@/models/index.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { publishInternalEvent } from "@/services/stream.js";
|
||||
|
|
|
@ -2,7 +2,7 @@ import define from "@/server/api/define.js";
|
|||
import readNote from "@/services/note/read.js";
|
||||
import { Antennas, Notes } from "@/models/index.js";
|
||||
import { redisClient } from "@/db/redis.js";
|
||||
import { getTimestamp } from "@/misc/gen-id.js";
|
||||
import { getTimestamp } from "backend-rs";
|
||||
import { makePaginationQuery } from "@/server/api/common/make-pagination-query.js";
|
||||
import { generateVisibilityQuery } from "@/server/api/common/generate-visibility-query.js";
|
||||
import { generateMutedUserQuery } from "@/server/api/common/generate-muted-user-query.js";
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { Apps } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId, secureRndstr } from "backend-rs";
|
||||
import { unique } from "@/prelude/array.js";
|
||||
import { secureRndstr } from "@/misc/secure-rndstr.js";
|
||||
|
||||
export const meta = {
|
||||
tags: ["app"],
|
||||
|
@ -41,7 +40,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
includeSecret: true,
|
||||
});
|
||||
// Generate secret
|
||||
const secret = secureRndstr(32, true);
|
||||
const secret = secureRndstr(32);
|
||||
|
||||
// for backward compatibility
|
||||
const permission = unique(
|
||||
|
|
|
@ -2,8 +2,7 @@ import * as crypto from "node:crypto";
|
|||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { AuthSessions, AccessTokens, Apps } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { secureRndstr } from "@/misc/secure-rndstr.js";
|
||||
import { genId, secureRndstr } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["auth"],
|
||||
|
@ -38,7 +37,7 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
}
|
||||
|
||||
// Generate access token
|
||||
const accessToken = secureRndstr(32, true);
|
||||
const accessToken = secureRndstr(32);
|
||||
|
||||
// Fetch exist access token
|
||||
const exist = await AccessTokens.exist({
|
||||
|
|
|
@ -3,7 +3,7 @@ import config from "@/config/index.js";
|
|||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { Apps, AuthSessions } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["auth"],
|
||||
|
|
|
@ -2,7 +2,7 @@ import define from "@/server/api/define.js";
|
|||
import { ApiError } from "@/server/api/error.js";
|
||||
import { Channels, DriveFiles } from "@/models/index.js";
|
||||
import type { Channel } from "@/models/entities/channel.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["channels"],
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { Channels, ChannelFollowings } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { publishUserEvent } from "@/services/stream.js";
|
||||
|
||||
export const meta = {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { ClipNotes, Clips } from "@/models/index.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { getNote } from "@/server/api/common/getters.js";
|
||||
|
||||
export const meta = {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { Clips } from "@/models/index.js";
|
||||
|
||||
export const meta = {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { publishDriveStream } from "@/services/stream.js";
|
|||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { DriveFolders } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["drive"],
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { DriveFiles, GalleryPosts } from "@/models/index.js";
|
||||
import { genId } from "@/server/api/../../misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { GalleryPost } from "@/models/entities/gallery-post.js";
|
||||
import type { DriveFile } from "@/models/entities/drive-file.js";
|
||||
import { HOUR } from "@/const.js";
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { GalleryPosts, GalleryLikes } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["gallery"],
|
||||
|
|
|
@ -2,7 +2,7 @@ import define from "@/server/api/define.js";
|
|||
import { UserProfiles, AttestationChallenges } from "@/models/index.js";
|
||||
import { promisify } from "node:util";
|
||||
import * as crypto from "node:crypto";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { hash } from "@/server/api/2fa.js";
|
||||
import { comparePassword } from "@/misc/password.js";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { AnnouncementReads, Announcements, Users } from "@/models/index.js";
|
||||
import { publishMainStream } from "@/services/stream.js";
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { publishMainStream } from "@/services/stream.js";
|
||||
import define from "@/server/api/define.js";
|
||||
import { RegistryItems } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { Webhooks } from "@/models/index.js";
|
||||
import { publishInternalEvent } from "@/services/stream.js";
|
||||
import { webhookEventTypes } from "@/models/entities/webhook.js";
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { AccessTokens } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { secureRndstr } from "@/misc/secure-rndstr.js";
|
||||
import { genId, secureRndstr } from "backend-rs";
|
||||
|
||||
export const meta = {
|
||||
tags: ["auth"],
|
||||
|
@ -44,7 +43,7 @@ export const paramDef = {
|
|||
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Generate access token
|
||||
const accessToken = secureRndstr(32, true);
|
||||
const accessToken = secureRndstr(32);
|
||||
|
||||
const now = new Date();
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { getUser } from "@/server/api/common/getters.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { Mutings, NoteWatchings } from "@/models/index.js";
|
||||
import type { Muting } from "@/models/entities/muting.js";
|
||||
import { publishUserEvent } from "@/services/stream.js";
|
||||
|
|
|
@ -26,7 +26,7 @@ import { concat } from "@/prelude/array.js";
|
|||
import { extractHashtags } from "@/misc/extract-hashtags.js";
|
||||
import { extractCustomEmojisFromMfm } from "@/misc/extract-custom-emojis-from-mfm.js";
|
||||
import { extractMentionedUsers } from "@/services/note/create.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { publishNoteStream } from "@/services/stream.js";
|
||||
import DeliverManager from "@/remote/activitypub/deliver-manager.js";
|
||||
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { NoteFavorites } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { getNote } from "@/server/api/common/getters.js";
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
Blockings,
|
||||
} from "@/models/index.js";
|
||||
import type { IRemoteUser } from "@/models/entities/user.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { getNote } from "@/server/api/common/getters.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Notes, NoteThreadMutings } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import readNote from "@/services/note/read.js";
|
||||
import define from "@/server/api/define.js";
|
||||
import { getNote } from "@/server/api/common/getters.js";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Pages, DriveFiles } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { Page } from "@/models/entities/page.js";
|
||||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Pages, PageLikes } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { PromoReads } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import define from "@/server/api/define.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import { getNote } from "@/server/api/common/getters.js";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { RenoteMutings } from "@/models/index.js";
|
||||
import { RenoteMuting } from "@/models/entities/renote-muting.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { ReplyMutings } from "@/models/index.js";
|
||||
import { ReplyMuting } from "@/models/entities/reply-muting.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
|
|
@ -3,7 +3,7 @@ import { IsNull } from "typeorm";
|
|||
import config from "@/config/index.js";
|
||||
import { Users, UserProfiles, PasswordResetRequests } from "@/models/index.js";
|
||||
import { sendEmail } from "@/services/send-email.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import define from "@/server/api/define.js";
|
||||
import { HOUR } from "@/const.js";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { SwSubscriptions } from "@/models/index.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { UserGroups, UserGroupJoinings } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { UserGroup } from "@/models/entities/user-group.js";
|
||||
import type { UserGroupJoining } from "@/models/entities/user-group-joining.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { UserGroupJoinings, UserGroupInvitations } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { UserGroupJoining } from "@/models/entities/user-group-joining.js";
|
||||
import { ApiError } from "@/server/api/error.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
|
|
@ -3,7 +3,7 @@ import {
|
|||
UserGroupJoinings,
|
||||
UserGroupInvitations,
|
||||
} from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { UserGroupInvitation } from "@/models/entities/user-group-invitation.js";
|
||||
import { createNotification } from "@/services/create-notification.js";
|
||||
import { getUser } from "@/server/api/common/getters.js";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { UserLists } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { UserList } from "@/models/entities/user-list.js";
|
||||
import define from "@/server/api/define.js";
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import * as mfm from "mfm-js";
|
|||
import sanitizeHtml from "sanitize-html";
|
||||
import { publishAdminStream } from "@/services/stream.js";
|
||||
import { AbuseUserReports, UserProfiles, Users } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { sendEmail } from "@/services/send-email.js";
|
||||
import { fetchMeta } from "@/misc/fetch-meta.js";
|
||||
import { getUser } from "@/server/api/common/getters.js";
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
AttestationChallenges,
|
||||
} from "@/models/index.js";
|
||||
import type { ILocalUser } from "@/models/entities/user.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import {
|
||||
comparePassword,
|
||||
hashPassword,
|
||||
|
|
|
@ -6,7 +6,7 @@ import { Users, RegistrationTickets, UserPendings } from "@/models/index.js";
|
|||
import { signup } from "@/server/api/common/signup.js";
|
||||
import config from "@/config/index.js";
|
||||
import { sendEmail } from "@/services/send-email.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { validateEmailForAccount } from "@/services/validate-email-for-account.js";
|
||||
import { hashPassword } from "@/misc/password.js";
|
||||
import { inspect } from "node:util";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type { Antenna } from "@/models/entities/antenna.js";
|
||||
import type { Note } from "@/models/entities/note.js";
|
||||
import { getTimestamp } from "@/misc/gen-id.js";
|
||||
import { getTimestamp } from "backend-rs";
|
||||
import { redisClient } from "@/db/redis.js";
|
||||
import { publishAntennaStream } from "@/services/stream.js";
|
||||
import type { User } from "@/models/entities/user.js";
|
||||
|
|
|
@ -15,7 +15,7 @@ import {
|
|||
UserListJoinings,
|
||||
UserLists,
|
||||
} from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { getActiveWebhooks } from "@/misc/webhook-cache.js";
|
||||
import { webhookDeliver } from "@/queue/index.js";
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
Users,
|
||||
Followings,
|
||||
} from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { User } from "@/models/entities/user.js";
|
||||
import type { Notification } from "@/models/entities/notification.js";
|
||||
import { sendEmailNotification } from "./send-email-notification.js";
|
||||
|
|
|
@ -4,7 +4,7 @@ import { genRsaKeyPair } from "@/misc/gen-key-pair.js";
|
|||
import { User } from "@/models/entities/user.js";
|
||||
import { UserProfile } from "@/models/entities/user-profile.js";
|
||||
import { IsNull } from "typeorm";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { UserKeypair } from "@/models/entities/user-keypair.js";
|
||||
import { UsedUsername } from "@/models/entities/used-username.js";
|
||||
import { db } from "@/db/postgre.js";
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
} from "@/models/index.js";
|
||||
import { DriveFile } from "@/models/entities/drive-file.js";
|
||||
import type { IRemoteUser, User } from "@/models/entities/user.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { isDuplicateKeyValueError } from "@/misc/is-duplicate-key-value-error.js";
|
||||
import { FILE_TYPE_BROWSERSAFE } from "@/const.js";
|
||||
import { IdentifiableError } from "@/misc/identifiable-error.js";
|
||||
|
|
|
@ -17,7 +17,7 @@ import {
|
|||
Instances,
|
||||
UserProfiles,
|
||||
} from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { createNotification } from "@/services/create-notification.js";
|
||||
import { isDuplicateKeyValueError } from "@/misc/is-duplicate-key-value-error.js";
|
||||
import type { Packed } from "@/misc/schema.js";
|
||||
|
|
|
@ -4,7 +4,7 @@ import renderFollow from "@/remote/activitypub/renderer/follow.js";
|
|||
import { deliver } from "@/queue/index.js";
|
||||
import type { User } from "@/models/entities/user.js";
|
||||
import { Blockings, FollowRequests, Users } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { createNotification } from "@/services/create-notification.js";
|
||||
import config from "@/config/index.js";
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import type { User } from "@/models/entities/user.js";
|
|||
import type { Note } from "@/models/entities/note.js";
|
||||
import { Notes, UserNotePinings, Users } from "@/models/index.js";
|
||||
import type { UserNotePining } from "@/models/entities/user-note-pining.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { deliverToFollowers } from "@/remote/activitypub/deliver-manager.js";
|
||||
import { deliverToRelays } from "@/services/relay.js";
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ModerationLogs } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { User } from "@/models/entities/user.js";
|
||||
|
||||
export async function insertModerationLog(
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
Mutings,
|
||||
Users,
|
||||
} from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { MessagingMessage } from "@/models/entities/messaging-message.js";
|
||||
import {
|
||||
publishMessagingStream,
|
||||
|
|
|
@ -37,7 +37,7 @@ import type { DriveFile } from "@/models/entities/drive-file.js";
|
|||
import type { App } from "@/models/entities/app.js";
|
||||
import { Not, In } from "typeorm";
|
||||
import type { User, ILocalUser, IRemoteUser } from "@/models/entities/user.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { activeUsersChart } from "@/services/chart/index.js";
|
||||
import type { IPoll } from "@/models/entities/poll.js";
|
||||
import { Poll } from "@/models/entities/poll.js";
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { CacheableUser } from "@/models/entities/user.js";
|
|||
import type { Note } from "@/models/entities/note.js";
|
||||
import { PollVotes, NoteWatchings, Polls, Blockings } from "@/models/index.js";
|
||||
import { Not } from "typeorm";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { createNotification } from "@/services/create-notification.js";
|
||||
|
||||
export default async function (
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
Blockings,
|
||||
} from "@/models/index.js";
|
||||
import { IsNull, Not } from "typeorm";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { createNotification } from "@/services/create-notification.js";
|
||||
import deleteReaction from "./delete.js";
|
||||
import { isDuplicateKeyValueError } from "@/misc/is-duplicate-key-value-error.js";
|
||||
|
|
|
@ -2,7 +2,7 @@ import type { Note } from "@/models/entities/note.js";
|
|||
import { publishMainStream } from "@/services/stream.js";
|
||||
import type { User } from "@/models/entities/user.js";
|
||||
import { Mutings, NoteThreadMutings, NoteUnreads } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
|
||||
export async function insertNoteUnread(
|
||||
userId: User["id"],
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import type { User } from "@/models/entities/user.js";
|
||||
import type { Note } from "@/models/entities/note.js";
|
||||
import { NoteWatchings } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { NoteWatching } from "@/models/entities/note-watching.js";
|
||||
|
||||
export default async (me: User["id"], note: Note) => {
|
||||
|
|
|
@ -3,7 +3,7 @@ import {
|
|||
MAX_LENGTH_INSTANCE,
|
||||
} from "@/models/entities/instance.js";
|
||||
import { Instances } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { toPuny } from "@/misc/convert-host.js";
|
||||
import { Cache } from "@/misc/cache.js";
|
||||
import Logger from "@/services/logger.js";
|
||||
|
|
|
@ -8,7 +8,7 @@ import renderUndo from "@/remote/activitypub/renderer/undo.js";
|
|||
import { deliver } from "@/queue/index.js";
|
||||
import type { ILocalUser, User } from "@/models/entities/user.js";
|
||||
import { Users, Relays } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { Cache } from "@/misc/cache.js";
|
||||
import type { Relay } from "@/models/entities/relay.js";
|
||||
import { createSystemUser } from "@/services/create-system-user.js";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type { User } from "@/models/entities/user.js";
|
||||
import { Hashtags, Users } from "@/models/index.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import type { Hashtag } from "@/models/entities/hashtag.js";
|
||||
import { normalizeForSearch } from "@/misc/normalize-for-search.js";
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import type { User } from "@/models/entities/user.js";
|
|||
import type { UserList } from "@/models/entities/user-list.js";
|
||||
import { UserListJoinings, Users } from "@/models/index.js";
|
||||
import type { UserListJoining } from "@/models/entities/user-list-joining.js";
|
||||
import { genId } from "@/misc/gen-id.js";
|
||||
import { genId } from "backend-rs";
|
||||
import { fetchProxyAccount } from "@/misc/fetch-proxy-account.js";
|
||||
import createFollowing from "@/services/following/create.js";
|
||||
|
||||
|
|
Loading…
Reference in a new issue