revert ap/show changes
This commit is contained in:
parent
515e24bf7d
commit
5a69868703
|
@ -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<typeof meta, typeof paramDef> { // 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<typeof meta, typeof paramDef> { // 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<typeof meta['res']> | 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<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を解決する
|
||||
*/
|
||||
@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)) {
|
||||
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.requestFailed);
|
||||
});
|
||||
|
||||
|
|
|
@ -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}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue