From 5a698687036698a95330a5557b96b5899d41f0cf Mon Sep 17 00:00:00 2001 From: tamaina Date: Sat, 30 Aug 2025 17:15:01 +0900 Subject: [PATCH] revert ap/show changes --- .../src/server/api/endpoints/ap/show.ts | 78 +------------------ .../test-federation/test/api/ap/show.test.ts | 29 +++---- 2 files changed, 16 insertions(+), 91 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/ap/show.ts b/packages/backend/src/server/api/endpoints/ap/show.ts index a3dc795df3..4afed7dc5c 100644 --- a/packages/backend/src/server/api/endpoints/ap/show.ts +++ b/packages/backend/src/server/api/endpoints/ap/show.ts @@ -5,7 +5,6 @@ import { Inject, Injectable } from '@nestjs/common'; import ms from 'ms'; -import * as misskey from 'misskey-js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import type { MiNote } from '@/models/Note.js'; import type { MiLocalUser, MiUser } from '@/models/User.js'; @@ -22,10 +21,6 @@ import { bindThis } from '@/decorators.js'; import { ApiError } from '../../error.js'; import { IdentifiableError } from '@/misc/identifiable-error.js'; import { FetchAllowSoftFailMask } from '@/core/activitypub/misc/check-against-url.js'; -import { RemoteUserResolveService } from '@/core/RemoteUserResolveService.js'; -import { DI } from '@/di-symbols.js'; -import type { MiMeta } from '@/models/_.js'; -import { ApiLoggerService } from '../../ApiLoggerService.js'; export const meta = { tags: ['federation'], @@ -64,16 +59,6 @@ export const meta = { code: 'NO_SUCH_OBJECT', id: 'dc94d745-1262-4e63-a17d-fecaa57efc82', }, - somethingHappenedInFetchingUri: { - message: 'Something happened while fetching the URI.', - code: 'SOMETHING_HAPPENED_IN_FETCHING_URI', - id: '14d45054-9df7-4f85-9e60-343b22f16b05', - }, - uriIsAcctLikeButThisIsOnlyUriFetchMode: { - message: 'URI is acct-like but onlyUriFetch is true.', - code: 'URI_IS_ACCT_LIKE_BUT_THIS_IS_ONLY_URI_FETCH_MODE', - id: 'b224ffe3-ae5c-44e2-9df4-f0b8662bb085', - }, }, res: { @@ -117,7 +102,6 @@ export const paramDef = { type: 'object', properties: { uri: { type: 'string' }, - onlyUriFetch: { type: 'boolean' }, }, required: ['uri'], } as const; @@ -125,9 +109,6 @@ export const paramDef = { @Injectable() export default class extends Endpoint { // eslint-disable-line import/no-default-export constructor( - @Inject(DI.meta) - private serverSettings: MiMeta, - private utilityService: UtilityService, private userEntityService: UserEntityService, private noteEntityService: NoteEntityService, @@ -135,46 +116,9 @@ export default class extends Endpoint { // eslint- private apDbResolverService: ApDbResolverService, private apPersonService: ApPersonService, private apNoteService: ApNoteService, - private remoteUserResolveService: RemoteUserResolveService, - private apiLoggerService: ApiLoggerService, ) { super(meta, paramDef, async (ps, me) => { - let object: SchemaType | null = null; - let acct: misskey.acct.Acct | null = null; - - try { - acct = misskey.acct.parseAcctOrUrl(ps.uri); - } catch (err) { - // nothing to do - } - - if (!ps.onlyUriFetch && acct) { - try { - object = await this.fetchAcct(acct, me); - } catch (err) { - if (err instanceof IdentifiableError && err.id === 'bddd9f4c-f0a8-4cac-9c0a-4e6d2fc43408') { - // Signin required - throw new ApiError(meta.errors.noSuchObject); - } - - this.apiLoggerService.logger.warn('ap/show: fetchAcct failed', { uri: ps.uri, error: err }); - } - } - - if (object == null) { - try { - object = await this.fetchAnyUri(ps.uri, me); - } catch (err) { - if (err instanceof ApiError) { - throw err; - } - if (acct) { - throw new ApiError(meta.errors.uriIsAcctLikeButThisIsOnlyUriFetchMode); - } - throw new ApiError(meta.errors.somethingHappenedInFetchingUri, err); - } - } - + const object = await this.fetchAny(ps.uri, me); if (object) { return object; } else { @@ -183,26 +127,11 @@ export default class extends Endpoint { // eslint- }); } - private async fetchAcct(acct: misskey.acct.Acct, me: MiLocalUser | null | undefined): Promise | null> { - if (this.serverSettings.ugcVisibilityForVisitor === 'local' && me == null) { - throw new IdentifiableError('bddd9f4c-f0a8-4cac-9c0a-4e6d2fc43408', 'Signin required'); - } - - const user = await this.remoteUserResolveService.resolveUser(acct.username, acct.host); - - if (!user) return null; - - return { - type: 'User', - object: await this.userEntityService.pack(user, me, { schema: 'UserDetailed' }), - }; - } - - /** + /*** * URIからUserかNoteを解決する */ @bindThis - private async fetchAnyUri(uri: string, me: MiLocalUser | null | undefined): Promise | null> { + private async fetchAny(uri: string, me: MiLocalUser | null | undefined): Promise | null> { if (!this.utilityService.isFederationAllowedUri(uri)) { throw new ApiError(meta.errors.federationNotAllowed); } @@ -245,6 +174,7 @@ export default class extends Endpoint { // eslint- throw new ApiError(meta.errors.responseInvalid); } } + throw new ApiError(meta.errors.requestFailed); }); diff --git a/packages/backend/test-federation/test/api/ap/show.test.ts b/packages/backend/test-federation/test/api/ap/show.test.ts index 30dbc9e396..eb949754d7 100644 --- a/packages/backend/test-federation/test/api/ap/show.test.ts +++ b/packages/backend/test-federation/test/api/ap/show.test.ts @@ -13,33 +13,28 @@ describe('API ap/show', () => { }); describe('User resolution', () => { - test('resolve by acct (bob@b.test)', async () => { - const res = await alice.client.request('ap/show', { uri: `${bob.username}@b.test` }); - strictEqual(res.type, 'User'); - strictEqual(res.object.uri, `https://b.test/users/${bob.id}`); - }); - test('resolve by canonical user URL (https://b.test/users/:id)', async () => { const res = await alice.client.request('ap/show', { uri: `https://b.test/users/${bob.id}` }); strictEqual(res.type, 'User'); strictEqual(res.object.uri, `https://b.test/users/${bob.id}`); }); - test('resolve by cross-origin non-canonical URL (https://a.test/@bob@b.test)', async () => { - const res = await alice.client.request('ap/show', { uri: `https://a.test/@${bob.username}@b.test` }); + test('resolve by user profile URL (https://b.test/@bob)', async () => { + const res = await alice.client.request('ap/show', { uri: `https://b.test/@${bob.username}` }); strictEqual(res.type, 'User'); - // 非正規URLから正規IDに追従して同一ユーザーになること strictEqual(res.object.uri, `https://b.test/users/${bob.id}`); }); - test('onlyUriFetch=true with acct string returns generic fetch error', async () => { - await rejects( - async () => await alice.client.request('ap/show', { uri: `${bob.username}@b.test`, onlyUriFetch: true }), - (err: any) => { - strictEqual(err.code, 'URI_IS_ACCT_LIKE_BUT_THIS_IS_ONLY_URI_FETCH_MODE'); - return true; - }, - ); + test('resolve local user by local profile url', async () => { + const res = await alice.client.request('ap/show', { uri: `https://a.test/@${alice.username}` }); + strictEqual(res.type, 'User'); + strictEqual(res.object.id, alice.id); + }); + + test('resolve remote user by local profile URL (https://a.test/@bob@b.test)', async () => { + const res = await alice.client.request('ap/show', { uri: `https://a.test/@${bob.username}@b.test` }); + strictEqual(res.type, 'User'); + strictEqual(res.object.uri, `https://b.test/users/${bob.id}`); }); });