diff --git a/packages/backend-rs/index.js b/packages/backend-rs/index.js index 0d2953fac8..e539b2a428 100644 --- a/packages/backend-rs/index.js +++ b/packages/backend-rs/index.js @@ -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 diff --git a/packages/backend-rs/src/util/id.rs b/packages/backend-rs/src/util/id.rs index 9d1427e65d..a37b3c2ea7 100644 --- a/packages/backend-rs/src/util/id.rs +++ b/packages/backend-rs/src/util/id.rs @@ -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 { +pub fn create_id(datetime: &NaiveDateTime) -> Result { 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>) -> 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); } } diff --git a/packages/backend-rs/src/util/random.rs b/packages/backend-rs/src/util/random.rs index ffcbca980f..b622d47534 100644 --- a/packages/backend-rs/src/util/random.rs +++ b/packages/backend-rs/src/util/random.rs @@ -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) -> String { + gen_string(length.unwrap_or(32)) } #[cfg(test)] diff --git a/packages/backend/src/boot/worker.ts b/packages/backend/src/boot/worker.ts index 0acdcd97c6..647ea40fbd 100644 --- a/packages/backend/src/boot/worker.ts +++ b/packages/backend/src/boot/worker.ts @@ -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") { diff --git a/packages/backend/src/misc/gen-id.ts b/packages/backend/src/misc/gen-id.ts index 4f5a0d5478..96d4ef55fa 100644 --- a/packages/backend/src/misc/gen-id.ts +++ b/packages/backend/src/misc/gen-id.ts @@ -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); diff --git a/packages/backend/src/misc/secure-rndstr.ts b/packages/backend/src/misc/secure-rndstr.ts deleted file mode 100644 index f98985592b..0000000000 --- a/packages/backend/src/misc/secure-rndstr.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { nativeRandomStr } from "backend-rs"; - -export function secureRndstr(length = 32, _ = true): string { - return nativeRandomStr(length); -} diff --git a/packages/backend/src/queue/processors/db/import-custom-emojis.ts b/packages/backend/src/queue/processors/db/import-custom-emojis.ts index 9e8b3b174e..f2371429f2 100644 --- a/packages/backend/src/queue/processors/db/import-custom-emojis.ts +++ b/packages/backend/src/queue/processors/db/import-custom-emojis.ts @@ -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"; diff --git a/packages/backend/src/queue/processors/db/import-firefish-post.ts b/packages/backend/src/queue/processors/db/import-firefish-post.ts index 4ec88d32cc..be412fc490 100644 --- a/packages/backend/src/queue/processors/db/import-firefish-post.ts +++ b/packages/backend/src/queue/processors/db/import-firefish-post.ts @@ -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"); diff --git a/packages/backend/src/queue/processors/db/import-masto-post.ts b/packages/backend/src/queue/processors/db/import-masto-post.ts index f42b003e9a..d8f848d206 100644 --- a/packages/backend/src/queue/processors/db/import-masto-post.ts +++ b/packages/backend/src/queue/processors/db/import-masto-post.ts @@ -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"); diff --git a/packages/backend/src/queue/processors/db/import-muting.ts b/packages/backend/src/queue/processors/db/import-muting.ts index acb7f22d55..cd42a3281d 100644 --- a/packages/backend/src/queue/processors/db/import-muting.ts +++ b/packages/backend/src/queue/processors/db/import-muting.ts @@ -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"; diff --git a/packages/backend/src/queue/processors/db/import-user-lists.ts b/packages/backend/src/queue/processors/db/import-user-lists.ts index 9c7d49c265..1ea6aa84ba 100644 --- a/packages/backend/src/queue/processors/db/import-user-lists.ts +++ b/packages/backend/src/queue/processors/db/import-user-lists.ts @@ -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"; diff --git a/packages/backend/src/remote/activitypub/kernel/flag/index.ts b/packages/backend/src/remote/activitypub/kernel/flag/index.ts index 39ba8b3f4f..0f83f6b449 100644 --- a/packages/backend/src/remote/activitypub/kernel/flag/index.ts +++ b/packages/backend/src/remote/activitypub/kernel/flag/index.ts @@ -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, diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index 3077ddb4f0..7d1d9d5aee 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -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"; diff --git a/packages/backend/src/remote/activitypub/models/person.ts b/packages/backend/src/remote/activitypub/models/person.ts index be8ba4a73f..d564275f3f 100644 --- a/packages/backend/src/remote/activitypub/models/person.ts +++ b/packages/backend/src/remote/activitypub/models/person.ts @@ -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"; diff --git a/packages/backend/src/server/api/common/generate-native-user-token.ts b/packages/backend/src/server/api/common/generate-native-user-token.ts index 5a8b41b70e..495a1150d2 100644 --- a/packages/backend/src/server/api/common/generate-native-user-token.ts +++ b/packages/backend/src/server/api/common/generate-native-user-token.ts @@ -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); diff --git a/packages/backend/src/server/api/common/signin.ts b/packages/backend/src/server/api/common/signin.ts index a8a435843f..e59a39ac41 100644 --- a/packages/backend/src/server/api/common/signin.ts +++ b/packages/backend/src/server/api/common/signin.ts @@ -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) { diff --git a/packages/backend/src/server/api/common/signup.ts b/packages/backend/src/server/api/common/signup.ts index dc76c264ae..7a8506b099 100644 --- a/packages/backend/src/server/api/common/signup.ts +++ b/packages/backend/src/server/api/common/signup.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/admin/ad/create.ts b/packages/backend/src/server/api/endpoints/admin/ad/create.ts index bfe4d54461..c7a56d3a98 100644 --- a/packages/backend/src/server/api/endpoints/admin/ad/create.ts +++ b/packages/backend/src/server/api/endpoints/admin/ad/create.ts @@ -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"], diff --git a/packages/backend/src/server/api/endpoints/admin/announcements/create.ts b/packages/backend/src/server/api/endpoints/admin/announcements/create.ts index 8af778486c..1ae25e62d0 100644 --- a/packages/backend/src/server/api/endpoints/admin/announcements/create.ts +++ b/packages/backend/src/server/api/endpoints/admin/announcements/create.ts @@ -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"], diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/add.ts b/packages/backend/src/server/api/endpoints/admin/emoji/add.ts index 8d4e756797..8fa7579ceb 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/add.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/add.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/copy.ts b/packages/backend/src/server/api/endpoints/admin/emoji/copy.ts index fad735b207..424baf4409 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/copy.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/copy.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/admin/invite.ts b/packages/backend/src/server/api/endpoints/admin/invite.ts index ebc523d418..d220ae5e4a 100644 --- a/packages/backend/src/server/api/endpoints/admin/invite.ts +++ b/packages/backend/src/server/api/endpoints/admin/invite.ts @@ -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"], diff --git a/packages/backend/src/server/api/endpoints/antennas/create.ts b/packages/backend/src/server/api/endpoints/antennas/create.ts index 46df3aa813..792301d4de 100644 --- a/packages/backend/src/server/api/endpoints/antennas/create.ts +++ b/packages/backend/src/server/api/endpoints/antennas/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/antennas/notes.ts b/packages/backend/src/server/api/endpoints/antennas/notes.ts index cbe0318525..f14b04372f 100644 --- a/packages/backend/src/server/api/endpoints/antennas/notes.ts +++ b/packages/backend/src/server/api/endpoints/antennas/notes.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/app/create.ts b/packages/backend/src/server/api/endpoints/app/create.ts index e32edf1293..0d52d5fbcf 100644 --- a/packages/backend/src/server/api/endpoints/app/create.ts +++ b/packages/backend/src/server/api/endpoints/app/create.ts @@ -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( diff --git a/packages/backend/src/server/api/endpoints/auth/accept.ts b/packages/backend/src/server/api/endpoints/auth/accept.ts index 088de7863b..f14fa5529e 100644 --- a/packages/backend/src/server/api/endpoints/auth/accept.ts +++ b/packages/backend/src/server/api/endpoints/auth/accept.ts @@ -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({ diff --git a/packages/backend/src/server/api/endpoints/auth/session/generate.ts b/packages/backend/src/server/api/endpoints/auth/session/generate.ts index bd17211044..26a1fddfcb 100644 --- a/packages/backend/src/server/api/endpoints/auth/session/generate.ts +++ b/packages/backend/src/server/api/endpoints/auth/session/generate.ts @@ -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"], diff --git a/packages/backend/src/server/api/endpoints/channels/create.ts b/packages/backend/src/server/api/endpoints/channels/create.ts index 177492ed29..29c6ca029a 100644 --- a/packages/backend/src/server/api/endpoints/channels/create.ts +++ b/packages/backend/src/server/api/endpoints/channels/create.ts @@ -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"], diff --git a/packages/backend/src/server/api/endpoints/channels/follow.ts b/packages/backend/src/server/api/endpoints/channels/follow.ts index 878339827a..fea6ca797b 100644 --- a/packages/backend/src/server/api/endpoints/channels/follow.ts +++ b/packages/backend/src/server/api/endpoints/channels/follow.ts @@ -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 = { diff --git a/packages/backend/src/server/api/endpoints/clips/add-note.ts b/packages/backend/src/server/api/endpoints/clips/add-note.ts index 887c8af083..2c34db5603 100644 --- a/packages/backend/src/server/api/endpoints/clips/add-note.ts +++ b/packages/backend/src/server/api/endpoints/clips/add-note.ts @@ -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 = { diff --git a/packages/backend/src/server/api/endpoints/clips/create.ts b/packages/backend/src/server/api/endpoints/clips/create.ts index df03b87b04..ae652d75c2 100644 --- a/packages/backend/src/server/api/endpoints/clips/create.ts +++ b/packages/backend/src/server/api/endpoints/clips/create.ts @@ -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 = { diff --git a/packages/backend/src/server/api/endpoints/drive/folders/create.ts b/packages/backend/src/server/api/endpoints/drive/folders/create.ts index 5581441980..9ea570a6b7 100644 --- a/packages/backend/src/server/api/endpoints/drive/folders/create.ts +++ b/packages/backend/src/server/api/endpoints/drive/folders/create.ts @@ -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"], diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts index a74f2165c2..7cf1d9f7c0 100644 --- a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts +++ b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/like.ts b/packages/backend/src/server/api/endpoints/gallery/posts/like.ts index f5ccc5bc68..13f7d82bb2 100644 --- a/packages/backend/src/server/api/endpoints/gallery/posts/like.ts +++ b/packages/backend/src/server/api/endpoints/gallery/posts/like.ts @@ -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"], diff --git a/packages/backend/src/server/api/endpoints/i/2fa/register-key.ts b/packages/backend/src/server/api/endpoints/i/2fa/register-key.ts index 78b68216ad..b275b5705d 100644 --- a/packages/backend/src/server/api/endpoints/i/2fa/register-key.ts +++ b/packages/backend/src/server/api/endpoints/i/2fa/register-key.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/i/read-announcement.ts b/packages/backend/src/server/api/endpoints/i/read-announcement.ts index a59d15b994..140eecfe67 100644 --- a/packages/backend/src/server/api/endpoints/i/read-announcement.ts +++ b/packages/backend/src/server/api/endpoints/i/read-announcement.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/i/registry/set.ts b/packages/backend/src/server/api/endpoints/i/registry/set.ts index 7a1f8ab5f7..7090f0914b 100644 --- a/packages/backend/src/server/api/endpoints/i/registry/set.ts +++ b/packages/backend/src/server/api/endpoints/i/registry/set.ts @@ -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, diff --git a/packages/backend/src/server/api/endpoints/i/webhooks/create.ts b/packages/backend/src/server/api/endpoints/i/webhooks/create.ts index ee38b76372..4faae058c3 100644 --- a/packages/backend/src/server/api/endpoints/i/webhooks/create.ts +++ b/packages/backend/src/server/api/endpoints/i/webhooks/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/miauth/gen-token.ts b/packages/backend/src/server/api/endpoints/miauth/gen-token.ts index bca09d3f07..d1527c51cf 100644 --- a/packages/backend/src/server/api/endpoints/miauth/gen-token.ts +++ b/packages/backend/src/server/api/endpoints/miauth/gen-token.ts @@ -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(); diff --git a/packages/backend/src/server/api/endpoints/mute/create.ts b/packages/backend/src/server/api/endpoints/mute/create.ts index 2eb935198e..a8d37153a4 100644 --- a/packages/backend/src/server/api/endpoints/mute/create.ts +++ b/packages/backend/src/server/api/endpoints/mute/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/notes/edit.ts b/packages/backend/src/server/api/endpoints/notes/edit.ts index 012f22bbd7..60d5258ce9 100644 --- a/packages/backend/src/server/api/endpoints/notes/edit.ts +++ b/packages/backend/src/server/api/endpoints/notes/edit.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/notes/favorites/create.ts b/packages/backend/src/server/api/endpoints/notes/favorites/create.ts index 8b2c7ad3a4..e2c7ca951f 100644 --- a/packages/backend/src/server/api/endpoints/notes/favorites/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/favorites/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/notes/polls/vote.ts b/packages/backend/src/server/api/endpoints/notes/polls/vote.ts index 1680eca640..9f67404875 100644 --- a/packages/backend/src/server/api/endpoints/notes/polls/vote.ts +++ b/packages/backend/src/server/api/endpoints/notes/polls/vote.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/notes/thread-muting/create.ts b/packages/backend/src/server/api/endpoints/notes/thread-muting/create.ts index 7c40a45923..b666e05835 100644 --- a/packages/backend/src/server/api/endpoints/notes/thread-muting/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/thread-muting/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/pages/create.ts b/packages/backend/src/server/api/endpoints/pages/create.ts index ea0f8ba83e..35ab2d0450 100644 --- a/packages/backend/src/server/api/endpoints/pages/create.ts +++ b/packages/backend/src/server/api/endpoints/pages/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/pages/like.ts b/packages/backend/src/server/api/endpoints/pages/like.ts index ab64b9b93e..1480b47e0b 100644 --- a/packages/backend/src/server/api/endpoints/pages/like.ts +++ b/packages/backend/src/server/api/endpoints/pages/like.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/promo/read.ts b/packages/backend/src/server/api/endpoints/promo/read.ts index 4b41467906..0509548b05 100644 --- a/packages/backend/src/server/api/endpoints/promo/read.ts +++ b/packages/backend/src/server/api/endpoints/promo/read.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/renote-mute/create.ts b/packages/backend/src/server/api/endpoints/renote-mute/create.ts index afe23f38da..46535cb39d 100644 --- a/packages/backend/src/server/api/endpoints/renote-mute/create.ts +++ b/packages/backend/src/server/api/endpoints/renote-mute/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/reply-mute/create.ts b/packages/backend/src/server/api/endpoints/reply-mute/create.ts index defe44ac05..fc8644a7e1 100644 --- a/packages/backend/src/server/api/endpoints/reply-mute/create.ts +++ b/packages/backend/src/server/api/endpoints/reply-mute/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/request-reset-password.ts b/packages/backend/src/server/api/endpoints/request-reset-password.ts index 3c78058af2..9855b06513 100644 --- a/packages/backend/src/server/api/endpoints/request-reset-password.ts +++ b/packages/backend/src/server/api/endpoints/request-reset-password.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/sw/register.ts b/packages/backend/src/server/api/endpoints/sw/register.ts index ee6b3bbf45..528d3106e0 100644 --- a/packages/backend/src/server/api/endpoints/sw/register.ts +++ b/packages/backend/src/server/api/endpoints/sw/register.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/users/groups/create.ts b/packages/backend/src/server/api/endpoints/users/groups/create.ts index 1cfb223013..e6ff909343 100644 --- a/packages/backend/src/server/api/endpoints/users/groups/create.ts +++ b/packages/backend/src/server/api/endpoints/users/groups/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/users/groups/invitations/accept.ts b/packages/backend/src/server/api/endpoints/users/groups/invitations/accept.ts index a483ccd184..f86f415d7a 100644 --- a/packages/backend/src/server/api/endpoints/users/groups/invitations/accept.ts +++ b/packages/backend/src/server/api/endpoints/users/groups/invitations/accept.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/users/groups/invite.ts b/packages/backend/src/server/api/endpoints/users/groups/invite.ts index 8a1e6b31ed..62e13a4458 100644 --- a/packages/backend/src/server/api/endpoints/users/groups/invite.ts +++ b/packages/backend/src/server/api/endpoints/users/groups/invite.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/users/lists/create.ts b/packages/backend/src/server/api/endpoints/users/lists/create.ts index c23e8f6f53..fa10bf24ce 100644 --- a/packages/backend/src/server/api/endpoints/users/lists/create.ts +++ b/packages/backend/src/server/api/endpoints/users/lists/create.ts @@ -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"; diff --git a/packages/backend/src/server/api/endpoints/users/report-abuse.ts b/packages/backend/src/server/api/endpoints/users/report-abuse.ts index 7e9ba7238c..1b43762cb6 100644 --- a/packages/backend/src/server/api/endpoints/users/report-abuse.ts +++ b/packages/backend/src/server/api/endpoints/users/report-abuse.ts @@ -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"; diff --git a/packages/backend/src/server/api/private/signin.ts b/packages/backend/src/server/api/private/signin.ts index af4fd65a7c..8692b01ad1 100644 --- a/packages/backend/src/server/api/private/signin.ts +++ b/packages/backend/src/server/api/private/signin.ts @@ -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, diff --git a/packages/backend/src/server/api/private/signup.ts b/packages/backend/src/server/api/private/signup.ts index ba6d23d28f..8179300884 100644 --- a/packages/backend/src/server/api/private/signup.ts +++ b/packages/backend/src/server/api/private/signup.ts @@ -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"; diff --git a/packages/backend/src/services/add-note-to-antenna.ts b/packages/backend/src/services/add-note-to-antenna.ts index 499418000d..66bc898263 100644 --- a/packages/backend/src/services/add-note-to-antenna.ts +++ b/packages/backend/src/services/add-note-to-antenna.ts @@ -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"; diff --git a/packages/backend/src/services/blocking/create.ts b/packages/backend/src/services/blocking/create.ts index 144304cfb3..2e5766c45b 100644 --- a/packages/backend/src/services/blocking/create.ts +++ b/packages/backend/src/services/blocking/create.ts @@ -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"; diff --git a/packages/backend/src/services/create-notification.ts b/packages/backend/src/services/create-notification.ts index 9bfd1a7bfa..a108d4f5de 100644 --- a/packages/backend/src/services/create-notification.ts +++ b/packages/backend/src/services/create-notification.ts @@ -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"; diff --git a/packages/backend/src/services/create-system-user.ts b/packages/backend/src/services/create-system-user.ts index 0ebd1142f1..345de7ad17 100644 --- a/packages/backend/src/services/create-system-user.ts +++ b/packages/backend/src/services/create-system-user.ts @@ -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"; diff --git a/packages/backend/src/services/drive/add-file.ts b/packages/backend/src/services/drive/add-file.ts index 65a51f926a..6320277eef 100644 --- a/packages/backend/src/services/drive/add-file.ts +++ b/packages/backend/src/services/drive/add-file.ts @@ -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"; diff --git a/packages/backend/src/services/following/create.ts b/packages/backend/src/services/following/create.ts index 3b8f63281d..7387346d1a 100644 --- a/packages/backend/src/services/following/create.ts +++ b/packages/backend/src/services/following/create.ts @@ -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"; diff --git a/packages/backend/src/services/following/requests/create.ts b/packages/backend/src/services/following/requests/create.ts index 12dfddf302..d2f2c1ca41 100644 --- a/packages/backend/src/services/following/requests/create.ts +++ b/packages/backend/src/services/following/requests/create.ts @@ -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"; diff --git a/packages/backend/src/services/i/pin.ts b/packages/backend/src/services/i/pin.ts index 3ee4cb4a80..2d2675a535 100644 --- a/packages/backend/src/services/i/pin.ts +++ b/packages/backend/src/services/i/pin.ts @@ -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"; diff --git a/packages/backend/src/services/insert-moderation-log.ts b/packages/backend/src/services/insert-moderation-log.ts index 8e2c5b78a1..9c76cf45ac 100644 --- a/packages/backend/src/services/insert-moderation-log.ts +++ b/packages/backend/src/services/insert-moderation-log.ts @@ -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( diff --git a/packages/backend/src/services/messages/create.ts b/packages/backend/src/services/messages/create.ts index 0b3f8eded9..f727c1846f 100644 --- a/packages/backend/src/services/messages/create.ts +++ b/packages/backend/src/services/messages/create.ts @@ -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, diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 2bd7442211..54e53c6c96 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -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"; diff --git a/packages/backend/src/services/note/polls/vote.ts b/packages/backend/src/services/note/polls/vote.ts index 6ade899726..32213ddcc8 100644 --- a/packages/backend/src/services/note/polls/vote.ts +++ b/packages/backend/src/services/note/polls/vote.ts @@ -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 ( diff --git a/packages/backend/src/services/note/reaction/create.ts b/packages/backend/src/services/note/reaction/create.ts index d9f45cc50a..a07ffdabad 100644 --- a/packages/backend/src/services/note/reaction/create.ts +++ b/packages/backend/src/services/note/reaction/create.ts @@ -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"; diff --git a/packages/backend/src/services/note/unread.ts b/packages/backend/src/services/note/unread.ts index cb87abe0e6..e00dcd07ac 100644 --- a/packages/backend/src/services/note/unread.ts +++ b/packages/backend/src/services/note/unread.ts @@ -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"], diff --git a/packages/backend/src/services/note/watch.ts b/packages/backend/src/services/note/watch.ts index 2a99dd6949..682b0822cc 100644 --- a/packages/backend/src/services/note/watch.ts +++ b/packages/backend/src/services/note/watch.ts @@ -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) => { diff --git a/packages/backend/src/services/register-or-fetch-instance-doc.ts b/packages/backend/src/services/register-or-fetch-instance-doc.ts index be26d8689b..a5481458a0 100644 --- a/packages/backend/src/services/register-or-fetch-instance-doc.ts +++ b/packages/backend/src/services/register-or-fetch-instance-doc.ts @@ -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"; diff --git a/packages/backend/src/services/relay.ts b/packages/backend/src/services/relay.ts index fdc42616ea..bd632ab1c1 100644 --- a/packages/backend/src/services/relay.ts +++ b/packages/backend/src/services/relay.ts @@ -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"; diff --git a/packages/backend/src/services/update-hashtag.ts b/packages/backend/src/services/update-hashtag.ts index a2b61664b4..05a899db6c 100644 --- a/packages/backend/src/services/update-hashtag.ts +++ b/packages/backend/src/services/update-hashtag.ts @@ -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"; diff --git a/packages/backend/src/services/user-list/push.ts b/packages/backend/src/services/user-list/push.ts index db01b0a900..141584e294 100644 --- a/packages/backend/src/services/user-list/push.ts +++ b/packages/backend/src/services/user-list/push.ts @@ -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";