chore: remove from/toMastodonId functions
This commit is contained in:
parent
fbe906fe11
commit
abaed389f9
5 changed files with 3 additions and 44 deletions
2
packages/backend-rs/index.d.ts
vendored
2
packages/backend-rs/index.d.ts
vendored
|
@ -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<string>
|
||||
export function toMastodonId(firefishId: string): string | null
|
||||
export function fromMastodonId(mastodonId: string): string | null
|
||||
export function fetchMeta(useCache: boolean): Promise<Meta>
|
||||
export interface PugArgs {
|
||||
img: string | null
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
#[crate::export]
|
||||
pub fn to_mastodon_id(firefish_id: &str) -> Option<String> {
|
||||
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<String> {
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue