revert ap/show changes
This commit is contained in:
parent
515e24bf7d
commit
5a69868703
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import ms from 'ms';
|
import ms from 'ms';
|
||||||
import * as misskey from 'misskey-js';
|
|
||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import type { MiNote } from '@/models/Note.js';
|
import type { MiNote } from '@/models/Note.js';
|
||||||
import type { MiLocalUser, MiUser } from '@/models/User.js';
|
import type { MiLocalUser, MiUser } from '@/models/User.js';
|
||||||
|
@ -22,10 +21,6 @@ import { bindThis } from '@/decorators.js';
|
||||||
import { ApiError } from '../../error.js';
|
import { ApiError } from '../../error.js';
|
||||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||||
import { FetchAllowSoftFailMask } from '@/core/activitypub/misc/check-against-url.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 = {
|
export const meta = {
|
||||||
tags: ['federation'],
|
tags: ['federation'],
|
||||||
|
@ -64,16 +59,6 @@ export const meta = {
|
||||||
code: 'NO_SUCH_OBJECT',
|
code: 'NO_SUCH_OBJECT',
|
||||||
id: 'dc94d745-1262-4e63-a17d-fecaa57efc82',
|
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: {
|
res: {
|
||||||
|
@ -117,7 +102,6 @@ export const paramDef = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
uri: { type: 'string' },
|
uri: { type: 'string' },
|
||||||
onlyUriFetch: { type: 'boolean' },
|
|
||||||
},
|
},
|
||||||
required: ['uri'],
|
required: ['uri'],
|
||||||
} as const;
|
} as const;
|
||||||
|
@ -125,9 +109,6 @@ export const paramDef = {
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.meta)
|
|
||||||
private serverSettings: MiMeta,
|
|
||||||
|
|
||||||
private utilityService: UtilityService,
|
private utilityService: UtilityService,
|
||||||
private userEntityService: UserEntityService,
|
private userEntityService: UserEntityService,
|
||||||
private noteEntityService: NoteEntityService,
|
private noteEntityService: NoteEntityService,
|
||||||
|
@ -135,46 +116,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
private apDbResolverService: ApDbResolverService,
|
private apDbResolverService: ApDbResolverService,
|
||||||
private apPersonService: ApPersonService,
|
private apPersonService: ApPersonService,
|
||||||
private apNoteService: ApNoteService,
|
private apNoteService: ApNoteService,
|
||||||
private remoteUserResolveService: RemoteUserResolveService,
|
|
||||||
private apiLoggerService: ApiLoggerService,
|
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(meta, paramDef, async (ps, me) => {
|
||||||
let object: SchemaType<typeof meta['res']> | null = null;
|
const object = await this.fetchAny(ps.uri, me);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (object) {
|
if (object) {
|
||||||
return object;
|
return object;
|
||||||
} else {
|
} else {
|
||||||
|
@ -183,26 +127,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async fetchAcct(acct: misskey.acct.Acct, me: MiLocalUser | null | undefined): Promise<SchemaType<typeof meta['res']> | 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を解決する
|
* URIからUserかNoteを解決する
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
private async fetchAnyUri(uri: string, me: MiLocalUser | null | undefined): Promise<SchemaType<typeof meta['res']> | null> {
|
private async fetchAny(uri: string, me: MiLocalUser | null | undefined): Promise<SchemaType<typeof meta['res']> | null> {
|
||||||
if (!this.utilityService.isFederationAllowedUri(uri)) {
|
if (!this.utilityService.isFederationAllowedUri(uri)) {
|
||||||
throw new ApiError(meta.errors.federationNotAllowed);
|
throw new ApiError(meta.errors.federationNotAllowed);
|
||||||
}
|
}
|
||||||
|
@ -245,6 +174,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
throw new ApiError(meta.errors.responseInvalid);
|
throw new ApiError(meta.errors.responseInvalid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ApiError(meta.errors.requestFailed);
|
throw new ApiError(meta.errors.requestFailed);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,33 +13,28 @@ describe('API ap/show', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('User resolution', () => {
|
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 () => {
|
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}` });
|
const res = await alice.client.request('ap/show', { uri: `https://b.test/users/${bob.id}` });
|
||||||
strictEqual(res.type, 'User');
|
strictEqual(res.type, 'User');
|
||||||
strictEqual(res.object.uri, `https://b.test/users/${bob.id}`);
|
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 () => {
|
test('resolve by user profile URL (https://b.test/@bob)', async () => {
|
||||||
const res = await alice.client.request('ap/show', { uri: `https://a.test/@${bob.username}@b.test` });
|
const res = await alice.client.request('ap/show', { uri: `https://b.test/@${bob.username}` });
|
||||||
strictEqual(res.type, 'User');
|
strictEqual(res.type, 'User');
|
||||||
// 非正規URLから正規IDに追従して同一ユーザーになること
|
|
||||||
strictEqual(res.object.uri, `https://b.test/users/${bob.id}`);
|
strictEqual(res.object.uri, `https://b.test/users/${bob.id}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('onlyUriFetch=true with acct string returns generic fetch error', async () => {
|
test('resolve local user by local profile url', async () => {
|
||||||
await rejects(
|
const res = await alice.client.request('ap/show', { uri: `https://a.test/@${alice.username}` });
|
||||||
async () => await alice.client.request('ap/show', { uri: `${bob.username}@b.test`, onlyUriFetch: true }),
|
strictEqual(res.type, 'User');
|
||||||
(err: any) => {
|
strictEqual(res.object.id, alice.id);
|
||||||
strictEqual(err.code, 'URI_IS_ACCT_LIKE_BUT_THIS_IS_ONLY_URI_FETCH_MODE');
|
});
|
||||||
return true;
|
|
||||||
},
|
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}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue