diff options
Diffstat (limited to 'packages/backend/src/core/activitypub')
5 files changed, 41 insertions, 39 deletions
diff --git a/packages/backend/src/core/activitypub/ApDbResolverService.ts b/packages/backend/src/core/activitypub/ApDbResolverService.ts index e9e0dde9cd..73b81a1226 100644 --- a/packages/backend/src/core/activitypub/ApDbResolverService.ts +++ b/packages/backend/src/core/activitypub/ApDbResolverService.ts @@ -64,7 +64,8 @@ export class ApDbResolverService implements OnApplicationShutdown { const apId = getApId(value); const uri = new URL(apId); - if (this.utilityService.toPuny(uri.host) !== this.utilityService.toPuny(this.config.host)) { + if ((this.utilityService.toPuny(uri.host) !== this.utilityService.toPuny(this.config.localHost)) && + (this.utilityService.toPuny(uri.host) !== this.utilityService.toPuny(this.config.webHost))) { return { local: false, uri: apId }; } diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts index 009d4cbd39..a7699c67d6 100644 --- a/packages/backend/src/core/activitypub/ApInboxService.ts +++ b/packages/backend/src/core/activitypub/ApInboxService.ts @@ -646,7 +646,7 @@ export class ApInboxService { const uris = getApIds(activity.object); const userIds = uris - .filter(uri => uri.startsWith(this.config.url + '/users/')) + .filter(uri => uri.startsWith(this.config.webUrl + '/users/')) .map(uri => uri.split('/').at(-1)) .filter(x => x != null); const users = await this.usersRepository.findBy({ diff --git a/packages/backend/src/core/activitypub/ApRendererService.ts b/packages/backend/src/core/activitypub/ApRendererService.ts index 9f55be11ac..aa014505ee 100644 --- a/packages/backend/src/core/activitypub/ApRendererService.ts +++ b/packages/backend/src/core/activitypub/ApRendererService.ts @@ -121,7 +121,7 @@ export class ApRendererService { } return { - id: `${this.config.url}/notes/${note.id}/activity`, + id: `${this.config.webUrl}/notes/${note.id}/activity`, actor: this.userEntityService.genLocalUserUri(note.userId), type: 'Announce', published: this.idService.parse(note.id).date.toISOString(), @@ -144,7 +144,7 @@ export class ApRendererService { return { type: 'Block', - id: `${this.config.url}/blocks/${block.id}`, + id: `${this.config.webUrl}/blocks/${block.id}`, actor: this.userEntityService.genLocalUserUri(block.blockerId), object: block.blockee.uri, }; @@ -153,7 +153,7 @@ export class ApRendererService { @bindThis public renderCreate(object: IObject, note: MiNote): ICreate { const activity: ICreate = { - id: `${this.config.url}/notes/${note.id}/activity`, + id: `${this.config.webUrl}/notes/${note.id}/activity`, actor: this.userEntityService.genLocalUserUri(note.userId), type: 'Create', published: this.idService.parse(note.id).date.toISOString(), @@ -191,7 +191,7 @@ export class ApRendererService { @bindThis public renderEmoji(emoji: MiEmoji): IApEmoji { return { - id: `${this.config.url}/emojis/${emoji.name}`, + id: `${this.config.webUrl}/emojis/${emoji.name}`, type: 'Emoji', name: `:${emoji.name}:`, updated: emoji.updatedAt != null ? emoji.updatedAt.toISOString() : new Date().toISOString(), @@ -222,7 +222,7 @@ export class ApRendererService { @bindThis public renderFollowRelay(relay: MiRelay, relayActor: MiLocalUser): IFollow { return { - id: `${this.config.url}/activities/follow-relay/${relay.id}`, + id: `${this.config.webUrl}/activities/follow-relay/${relay.id}`, type: 'Follow', actor: this.userEntityService.genLocalUserUri(relayActor.id), object: 'https://www.w3.org/ns/activitystreams#Public', @@ -246,7 +246,7 @@ export class ApRendererService { requestId?: string, ): IFollow { return { - id: requestId ?? `${this.config.url}/follows/${follower.id}/${followee.id}`, + id: requestId ?? `${this.config.webUrl}/follows/${follower.id}/${followee.id}`, type: 'Follow', actor: this.userEntityService.getUserUri(follower), object: this.userEntityService.getUserUri(followee), @@ -257,7 +257,7 @@ export class ApRendererService { public renderHashtag(tag: string): IApHashtag { return { type: 'Hashtag', - href: `${this.config.url}/tags/${encodeURIComponent(tag)}`, + href: `${this.config.webUrl}/tags/${encodeURIComponent(tag)}`, name: `#${tag}`, }; } @@ -318,7 +318,7 @@ export class ApRendererService { @bindThis public renderKey(user: MiLocalUser, key: MiUserKeypair, postfix?: string): IKey { return { - id: `${this.config.url}/users/${user.id}${postfix ?? '/publickey'}`, + id: `${this.config.webUrl}/users/${user.id}${postfix ?? '/publickey'}`, type: 'Key', owner: this.userEntityService.genLocalUserUri(user.id), publicKeyPem: createPublicKey(key.publicKey).export({ @@ -348,9 +348,9 @@ export class ApRendererService { const object: ILike = { type: 'Like', - id: `${this.config.url}/likes/${noteReaction.id}`, - actor: `${this.config.url}/users/${noteReaction.userId}`, - object: note.uri ? note.uri : `${this.config.url}/notes/${noteReaction.noteId}`, + id: `${this.config.webUrl}/likes/${noteReaction.id}`, + actor: `${this.config.webUrl}/users/${noteReaction.userId}`, + object: note.uri ? note.uri : `${this.config.webUrl}/notes/${noteReaction.noteId}`, content: isMastodon ? undefined : reaction, _misskey_reaction: isMastodon ? undefined : reaction, }; @@ -382,7 +382,7 @@ export class ApRendererService { const actor = this.userEntityService.getUserUri(src); const target = this.userEntityService.getUserUri(dst); return { - id: `${this.config.url}/moves/${src.id}/${dst.id}`, + id: `${this.config.webUrl}/moves/${src.id}/${dst.id}`, actor, type: 'Move', object: actor, @@ -414,7 +414,7 @@ export class ApRendererService { if (dive) { inReplyTo = await this.renderNote(inReplyToNote, inReplyToUser, false); } else { - inReplyTo = `${this.config.url}/notes/${inReplyToNote.id}`; + inReplyTo = `${this.config.webUrl}/notes/${inReplyToNote.id}`; } } } @@ -429,7 +429,7 @@ export class ApRendererService { const renote = await this.notesRepository.findOneBy({ id: note.renoteId }); if (renote) { - quote = renote.uri ? renote.uri : `${this.config.url}/notes/${renote.id}`; + quote = renote.uri ? renote.uri : `${this.config.webUrl}/notes/${renote.id}`; } } @@ -540,7 +540,7 @@ export class ApRendererService { const replies = isPublic ? await this.renderRepliesCollection(note.id) : undefined; return { - id: `${this.config.url}/notes/${note.id}`, + id: `${this.config.webUrl}/notes/${note.id}`, type: 'Note', attributedTo, summary: summary ?? undefined, @@ -608,9 +608,9 @@ export class ApRendererService { followers: `${id}/followers`, following: `${id}/following`, featured: `${id}/collections/featured`, - sharedInbox: `${this.config.url}/inbox`, - endpoints: { sharedInbox: `${this.config.url}/inbox` }, - url: `${this.config.url}/@${user.username}`, + sharedInbox: `${this.config.webUrl}/inbox`, + endpoints: { sharedInbox: `${this.config.webUrl}/inbox` }, + url: `${this.config.webUrl}/@${user.username}`, preferredUsername: user.username, name: user.name, summary: profile.description ? this.mfmService.toHtml(mfm.parse(profile.description)) : null, @@ -672,9 +672,9 @@ export class ApRendererService { id, inbox: `${id}/inbox`, outbox: `${id}/outbox`, - sharedInbox: `${this.config.url}/inbox`, - endpoints: { sharedInbox: `${this.config.url}/inbox` }, - url: `${this.config.url}/@${user.username}`, + sharedInbox: `${this.config.webUrl}/inbox`, + endpoints: { sharedInbox: `${this.config.webUrl}/inbox` }, + url: `${this.config.webUrl}/@${user.username}`, preferredUsername: user.username, publicKey: this.renderKey(user, keypair, '#main-key'), @@ -695,7 +695,7 @@ export class ApRendererService { public renderQuestion(user: { id: MiUser['id'] }, note: MiNote, poll: MiPoll): IQuestion { return { type: 'Question', - id: `${this.config.url}/questions/${note.id}`, + id: `${this.config.webUrl}/questions/${note.id}`, actor: this.userEntityService.genLocalUserUri(user.id), content: note.text ?? '', [poll.multiple ? 'anyOf' : 'oneOf']: poll.choices.map((text, i) => ({ @@ -752,7 +752,7 @@ export class ApRendererService { @bindThis public renderUpdate(object: string | IObject, user: { id: MiUser['id'] }): IUpdate { return { - id: `${this.config.url}/users/${user.id}#updates/${new Date().getTime()}`, + id: `${this.config.webUrl}/users/${user.id}#updates/${new Date().getTime()}`, actor: this.userEntityService.genLocalUserUri(user.id), type: 'Update', to: ['https://www.w3.org/ns/activitystreams#Public'], @@ -764,13 +764,13 @@ export class ApRendererService { @bindThis public renderVote(user: { id: MiUser['id'] }, vote: MiPollVote, note: MiNote, poll: MiPoll, pollOwner: MiRemoteUser): ICreate { return { - id: `${this.config.url}/users/${user.id}#votes/${vote.id}/activity`, + id: `${this.config.webUrl}/users/${user.id}#votes/${vote.id}/activity`, actor: this.userEntityService.genLocalUserUri(user.id), type: 'Create', to: [pollOwner.uri], published: new Date().toISOString(), object: { - id: `${this.config.url}/users/${user.id}#votes/${vote.id}`, + id: `${this.config.webUrl}/users/${user.id}#votes/${vote.id}`, type: 'Note', attributedTo: this.userEntityService.genLocalUserUri(user.id), to: [pollOwner.uri], @@ -783,7 +783,7 @@ export class ApRendererService { @bindThis public addContext<T extends IObject>(x: T): T & { '@context': any; id: string; } { if (typeof x === 'object' && x.id == null) { - x.id = `${this.config.url}/${randomUUID()}`; + x.id = `${this.config.webUrl}/${randomUUID()}`; } return Object.assign({ '@context': CONTEXT }, x as T & { id: string }); @@ -800,7 +800,7 @@ export class ApRendererService { const keypair = await this.userKeypairService.getUserKeypair(user.id); - activity = await this.jsonLdService.signRsaSignature2017(activity, keypair.privateKey, `${this.config.url}/users/${user.id}#main-key`); + activity = await this.jsonLdService.signRsaSignature2017(activity, keypair.privateKey, `${this.config.webUrl}/users/${user.id}#main-key`); return activity; } @@ -867,8 +867,8 @@ export class ApRendererService { return { type: 'OrderedCollection', - id: `${this.config.url}/notes/${noteId}/replies`, - first: `${this.config.url}/notes/${noteId}/replies?page=true`, + id: `${this.config.webUrl}/notes/${noteId}/replies`, + first: `${this.config.webUrl}/notes/${noteId}/replies?page=true`, totalItems: replyCount, }; } @@ -898,18 +898,18 @@ export class ApRendererService { .getRawMany<{ note_id: string, note_uri: string | null }>(); const hasNextPage = results.length >= limit; - const baseId = `${this.config.url}/notes/${noteId}/replies?page=true`; + const baseId = `${this.config.webUrl}/notes/${noteId}/replies?page=true`; return { type: 'OrderedCollectionPage', id: untilId == null ? baseId : `${baseId}&until_id=${untilId}`, - partOf: `${this.config.url}/notes/${noteId}/replies`, + partOf: `${this.config.webUrl}/notes/${noteId}/replies`, first: baseId, next: hasNextPage ? `${baseId}&until_id=${results.at(-1)?.note_id}` : undefined, totalItems: replyCount, orderedItems: results.map(r => { // Remote notes have a URI, local have just an ID. - return r.note_uri ?? `${this.config.url}/notes/${r.note_id}`; + return r.note_uri ?? `${this.config.webUrl}/notes/${r.note_id}`; }), }; } @@ -920,7 +920,7 @@ export class ApRendererService { if (isPureRenote(note)) { const renote = hint?.renote ?? note.renote ?? await this.notesRepository.findOneByOrFail({ id: note.renoteId }); - const apAnnounce = this.renderAnnounce(renote.uri ?? `${this.config.url}/notes/${renote.id}`, note); + const apAnnounce = this.renderAnnounce(renote.uri ?? `${this.config.webUrl}/notes/${renote.id}`, note); return this.addContext(apAnnounce); } diff --git a/packages/backend/src/core/activitypub/ApRequestService.ts b/packages/backend/src/core/activitypub/ApRequestService.ts index 7669ce9669..cd92adc549 100644 --- a/packages/backend/src/core/activitypub/ApRequestService.ts +++ b/packages/backend/src/core/activitypub/ApRequestService.ts @@ -164,7 +164,7 @@ export class ApRequestService { const req = ApRequestCreator.createSignedPost({ key: { privateKeyPem: keypair.privateKey, - keyId: `${this.config.url}/users/${user.id}#main-key`, + keyId: `${this.config.webUrl}/users/${user.id}#main-key`, }, url, body, @@ -195,7 +195,7 @@ export class ApRequestService { const req = ApRequestCreator.createSignedGet({ key: { privateKeyPem: keypair.privateKey, - keyId: `${this.config.url}/users/${user.id}#main-key`, + keyId: `${this.config.webUrl}/users/${user.id}#main-key`, }, url, additionalHeaders: { diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index f1a2522c04..8870395a1b 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -252,7 +252,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown { if (cached) return cached; // URIがこのサーバーを指しているならデータベースからフェッチ - if (uri.startsWith(`${this.config.url}/`)) { + if (uri.startsWith(`${this.config.webUrl}/`) || uri.startsWith(`${this.config.localUrl}/`)) { const id = uri.split('/').pop(); const u = await this.usersRepository.findOneBy({ id }) as MiLocalUser | null; if (u) this.cacheService.uriPersonCache.set(uri, u); @@ -327,7 +327,8 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown { if (typeof uri !== 'string') throw new UnrecoverableError(`failed to create user ${uri}: input is not string`); const host = this.utilityService.punyHost(uri); - if (host === this.utilityService.toPuny(this.config.host)) { + if ((host === this.utilityService.toPuny(this.config.localHost)) || + (host === this.utilityService.toPuny(this.config.webHost))) { throw new UnrecoverableError(`failed to create user ${uri}: URI is local`); } |