summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/backend/src/core/activitypub/ApDbResolverService.ts32
1 files changed, 12 insertions, 20 deletions
diff --git a/packages/backend/src/core/activitypub/ApDbResolverService.ts b/packages/backend/src/core/activitypub/ApDbResolverService.ts
index 2d9e7a14ee..ca148916dc 100644
--- a/packages/backend/src/core/activitypub/ApDbResolverService.ts
+++ b/packages/backend/src/core/activitypub/ApDbResolverService.ts
@@ -1,5 +1,4 @@
import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';
-import escapeRegexp from 'escape-regexp';
import { DI } from '@/di-symbols.js';
import type { NotesRepository, UserPublickeysRepository, UsersRepository } from '@/models/index.js';
import type { Config } from '@/config.js';
@@ -56,25 +55,18 @@ export class ApDbResolverService implements OnApplicationShutdown {
@bindThis
public parseUri(value: string | IObject): UriParseResult {
- const uri = getApId(value);
-
- // the host part of a URL is case insensitive, so use the 'i' flag.
- const localRegex = new RegExp('^' + escapeRegexp(this.config.url) + '/(\\w+)/(\\w+)(?:\/(.+))?', 'i');
- const matchLocal = uri.match(localRegex);
-
- if (matchLocal) {
- return {
- local: true,
- type: matchLocal[1],
- id: matchLocal[2],
- rest: matchLocal[3],
- };
- } else {
- return {
- local: false,
- uri,
- };
- }
+ const separator = '/';
+
+ const uri = new URL(getApId(value));
+ if (uri.origin !== this.config.url) return { local: false, uri: uri.href };
+
+ const [, type, id, ...rest] = uri.pathname.split(separator);
+ return {
+ local: true,
+ type,
+ id,
+ rest: rest.length === 0 ? undefined : rest.join(separator),
+ };
}
/**