From f37614b751ce0036272365152bd6e74add2e4935 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Mon, 15 Sep 2025 17:56:26 -0400 Subject: [PATCH] move parseUri from ApDbResolverService to UtilityService --- packages/backend/src/core/UtilityService.ts | 36 +++++++++++++++++++ .../core/activitypub/ApDbResolverService.ts | 35 +++--------------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/packages/backend/src/core/UtilityService.ts b/packages/backend/src/core/UtilityService.ts index 8ebf7e6f52..63b16a55d8 100644 --- a/packages/backend/src/core/UtilityService.ts +++ b/packages/backend/src/core/UtilityService.ts @@ -16,6 +16,22 @@ import type { MiInstance } from '@/models/Instance.js'; import { IdentifiableError } from '@/misc/identifiable-error.js'; import { EnvService } from '@/global/EnvService.js'; +export type UriParseResult = { + /** wether the URI was generated by us */ + local: true; + /** id in DB */ + id: string; + /** hint of type, e.g. "notes", "users" */ + type: string; + /** any remaining text after type and id, not including the slash after id. undefined if empty */ + rest?: string; +} | { + /** wether the URI was generated by us */ + local: false; + /** uri in DB */ + uri: string; +}; + @Injectable() export class UtilityService { constructor( @@ -302,4 +318,24 @@ export class UtilityService { return false; } } + + // Moved from ApPersonService to avoid circular dependency + @bindThis + public parseUri(value: string | IObject | [string | IObject]): UriParseResult { + const separator = '/'; + + const apId = getApId(value); + const uri = new URL(apId); + if (this.toPuny(uri.host) !== this.toPuny(this.config.host)) { + return { local: false, uri: apId }; + } + + const [, type, id, ...rest] = uri.pathname.split(separator); + return { + local: true, + type, + id, + rest: rest.length === 0 ? undefined : rest.join(separator), + }; + } } diff --git a/packages/backend/src/core/activitypub/ApDbResolverService.ts b/packages/backend/src/core/activitypub/ApDbResolverService.ts index a5eb851d6c..f79d6a86a8 100644 --- a/packages/backend/src/core/activitypub/ApDbResolverService.ts +++ b/packages/backend/src/core/activitypub/ApDbResolverService.ts @@ -19,21 +19,7 @@ import { getApId } from './type.js'; import { ApPersonService } from './models/ApPersonService.js'; import type { IObject } from './type.js'; -export type UriParseResult = { - /** wether the URI was generated by us */ - local: true; - /** id in DB */ - id: string; - /** hint of type, e.g. "notes", "users" */ - type: string; - /** any remaining text after type and id, not including the slash after id. undefined if empty */ - rest?: string; -} | { - /** wether the URI was generated by us */ - local: false; - /** uri in DB */ - uri: string; -}; +export type { UriParseResult } from '@/core/UtilityService.js'; @Injectable() export class ApDbResolverService implements OnApplicationShutdown { @@ -58,23 +44,10 @@ export class ApDbResolverService implements OnApplicationShutdown { // Caches moved to ApPersonService to avoid circular dependency } + // Moved to UtilityService to avoid circular dependency @bindThis - public parseUri(value: string | IObject | [string | IObject]): UriParseResult { - const separator = '/'; - - const apId = getApId(value); - const uri = new URL(apId); - if (this.utilityService.toPuny(uri.host) !== this.utilityService.toPuny(this.config.host)) { - return { local: false, uri: apId }; - } - - const [, type, id, ...rest] = uri.pathname.split(separator); - return { - local: true, - type, - id, - rest: rest.length === 0 ? undefined : rest.join(separator), - }; + public parseUri(value: string | IObject | [string | IObject]) { + return this.utilityService.parseUri(value); } /**