From abaed389f9935577d26a6265684bcf9464ee80f3 Mon Sep 17 00:00:00 2001 From: naskya Date: Fri, 24 May 2024 09:31:34 +0900 Subject: [PATCH] chore: remove from/toMastodonId functions --- packages/backend-rs/index.d.ts | 2 -- packages/backend-rs/index.js | 4 +-- packages/backend-rs/src/misc/mastodon_id.rs | 35 ------------------- packages/backend-rs/src/misc/mod.rs | 1 - .../src/server/api/mastodon/helpers/auth.ts | 5 ++- 5 files changed, 3 insertions(+), 44 deletions(-) delete mode 100644 packages/backend-rs/src/misc/mastodon_id.rs diff --git a/packages/backend-rs/index.d.ts b/packages/backend-rs/index.d.ts index 4253dbf730..48663ade3b 100644 --- a/packages/backend-rs/index.d.ts +++ b/packages/backend-rs/index.d.ts @@ -260,8 +260,6 @@ export function getNoteSummary(note: NoteLikeForGetNoteSummary): string export function isQuote(note: Note): boolean export function isSafeUrl(url: string): boolean export function latestVersion(): Promise -export function toMastodonId(firefishId: string): string | null -export function fromMastodonId(mastodonId: string): string | null export function fetchMeta(useCache: boolean): Promise export interface PugArgs { img: string | null diff --git a/packages/backend-rs/index.js b/packages/backend-rs/index.js index c86f0f27d6..329c08a8c6 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 { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, loadEnv, loadConfig, stringToAcct, acctToString, greet, initializeRustLogger, showServerInfo, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, sqlRegexEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, isQuote, isSafeUrl, latestVersion, toMastodonId, fromMastodonId, fetchMeta, metaToPugArgs, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, cpuInfo, cpuUsage, memoryUsage, storageUsage, AntennaSrc, DriveFileUsageHint, MutedNoteReason, NoteVisibility, NotificationType, PageVisibility, PollNoteVisibility, RelayStatus, UserEmojiModPerm, UserProfileFfvisibility, UserProfileMutingNotificationTypes, updateAntennasOnNewNote, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, watchNote, unwatchNote, PushNotificationKind, sendPushNotification, publishToChannelStream, ChatEvent, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, getTimestamp, genId, genIdAt, generateSecureRandomString, generateUserToken } = nativeBinding +const { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, loadEnv, loadConfig, stringToAcct, acctToString, greet, initializeRustLogger, showServerInfo, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, sqlRegexEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, isQuote, isSafeUrl, latestVersion, fetchMeta, metaToPugArgs, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, cpuInfo, cpuUsage, memoryUsage, storageUsage, AntennaSrc, DriveFileUsageHint, MutedNoteReason, NoteVisibility, NotificationType, PageVisibility, PollNoteVisibility, RelayStatus, UserEmojiModPerm, UserProfileFfvisibility, UserProfileMutingNotificationTypes, updateAntennasOnNewNote, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, watchNote, unwatchNote, PushNotificationKind, sendPushNotification, publishToChannelStream, ChatEvent, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, getTimestamp, genId, genIdAt, generateSecureRandomString, generateUserToken } = nativeBinding module.exports.SECOND = SECOND module.exports.MINUTE = MINUTE @@ -345,8 +345,6 @@ module.exports.getNoteSummary = getNoteSummary module.exports.isQuote = isQuote module.exports.isSafeUrl = isSafeUrl module.exports.latestVersion = latestVersion -module.exports.toMastodonId = toMastodonId -module.exports.fromMastodonId = fromMastodonId module.exports.fetchMeta = fetchMeta module.exports.metaToPugArgs = metaToPugArgs module.exports.nyaify = nyaify diff --git a/packages/backend-rs/src/misc/mastodon_id.rs b/packages/backend-rs/src/misc/mastodon_id.rs deleted file mode 100644 index 9cf5d8d5f5..0000000000 --- a/packages/backend-rs/src/misc/mastodon_id.rs +++ /dev/null @@ -1,35 +0,0 @@ -#[crate::export] -pub fn to_mastodon_id(firefish_id: &str) -> Option { - let decoded: [u8; 16] = basen::BASE36.decode_var_len(firefish_id)?; - Some(basen::BASE10.encode_var_len(&decoded)) -} - -#[crate::export] -pub fn from_mastodon_id(mastodon_id: &str) -> Option { - let decoded: [u8; 16] = basen::BASE10.decode_var_len(mastodon_id)?; - Some(basen::BASE36.encode_var_len(&decoded)) -} - -#[cfg(test)] -mod unit_test { - use super::{from_mastodon_id, to_mastodon_id}; - use pretty_assertions::assert_eq; - - #[test] - fn to_mastodon_id_test() { - assert_eq!( - to_mastodon_id("9pdqi3rjl4lxirq3").unwrap(), - "2145531976185871567229403" - ); - assert_eq!(to_mastodon_id("9pdqi3r*irq3"), None); - } - - #[test] - fn from_mastodon_id_test() { - assert_eq!( - from_mastodon_id("2145531976185871567229403").unwrap(), - "9pdqi3rjl4lxirq3" - ); - assert_eq!(from_mastodon_id("9pdqi3rjl4lxirq3"), None); - } -} diff --git a/packages/backend-rs/src/misc/mod.rs b/packages/backend-rs/src/misc/mod.rs index 3aefacc48c..d0e60b5def 100644 --- a/packages/backend-rs/src/misc/mod.rs +++ b/packages/backend-rs/src/misc/mod.rs @@ -10,7 +10,6 @@ pub mod get_note_summary; pub mod is_quote; pub mod is_safe_url; pub mod latest_version; -pub mod mastodon_id; pub mod meta; pub mod nyaify; pub mod password; diff --git a/packages/backend/src/server/api/mastodon/helpers/auth.ts b/packages/backend/src/server/api/mastodon/helpers/auth.ts index 01ada28bfe..ec3ad5c263 100644 --- a/packages/backend/src/server/api/mastodon/helpers/auth.ts +++ b/packages/backend/src/server/api/mastodon/helpers/auth.ts @@ -2,13 +2,12 @@ import type OAuth from "@/server/api/mastodon/entities/oauth/oauth.js"; import { generateSecureRandomString } from "backend-rs"; import { Apps, AccessTokens } from "@/models/index.js"; import { genId } from "backend-rs"; -import { fetchMeta } from "backend-rs"; +import { fetchMeta, getTimestamp } from "backend-rs"; import type { MastoContext } from "@/server/api/mastodon/index.js"; import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js"; import { difference, toSingleLast, unique } from "@/prelude/array.js"; import type { ILocalUser } from "@/models/entities/user.js"; import type { App } from "@/models/entities/app"; -import { toMastodonId } from "backend-rs"; export class AuthHelpers { public static async registerApp( @@ -61,7 +60,7 @@ export class AuthHelpers { // Compatibility: ZonePane only accepts a small int as app ID id: app.name === "ZonePane" - ? toMastodonId(app.id)?.substring(0, 6) ?? app.id + ? getTimestamp(app.id)?.toString().substring(0, 6) ?? app.id : app.id, name: app.name, website: app.description,