This commit is contained in:
tamaina 2023-06-04 15:34:11 +00:00
parent aead5305a7
commit 8bad11c559
5 changed files with 119 additions and 100 deletions

View File

@ -3,40 +3,14 @@ import ms from 'ms';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { ApResolverService } from '@/core/activitypub/ApResolverService.js';
export const meta = {
tags: ['federation'],
requireCredential: true,
limit: {
duration: ms('1hour'),
max: 30,
},
errors: {
},
res: {
type: 'object',
optional: false, nullable: false,
},
} as const;
export const paramDef = {
type: 'object',
properties: {
uri: { type: 'string' },
},
required: ['uri'],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'ap/get'> {
name = 'ap/get' as const;
constructor(
private apResolverService: ApResolverService,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
const resolver = this.apResolverService.createResolver();
const object = await resolver.resolve(ps.uri);
return object;

View File

@ -17,73 +17,13 @@ import { UtilityService } from '@/core/UtilityService.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { ApiError } from '../../error.js';
export const meta = {
tags: ['federation'],
requireCredential: true,
limit: {
duration: ms('1hour'),
max: 30,
},
errors: {
noSuchObject: {
message: 'No such object.',
code: 'NO_SUCH_OBJECT',
id: 'dc94d745-1262-4e63-a17d-fecaa57efc82',
},
},
res: {
optional: false, nullable: false,
oneOf: [
{
type: 'object',
properties: {
type: {
type: 'string',
optional: false, nullable: false,
enum: ['User'],
},
object: {
type: 'object',
optional: false, nullable: false,
ref: 'UserDetailedNotMe',
},
},
},
{
type: 'object',
properties: {
type: {
type: 'string',
optional: false, nullable: false,
enum: ['Note'],
},
object: {
type: 'object',
optional: false, nullable: false,
ref: 'Note',
},
},
},
],
},
} as const;
export const paramDef = {
type: 'object',
properties: {
uri: { type: 'string' },
},
required: ['uri'],
} as const;
import { Endpoints } from 'misskey-js';
import { References } from 'misskey-js/built/schemas.js';
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'ap/show'> {
name = 'ap/show' as const;
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
@ -100,12 +40,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private apPersonService: ApPersonService,
private apNoteService: ApNoteService,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
const object = await this.fetchAny(ps.uri, me);
if (object) {
return object;
} else {
throw new ApiError(meta.errors.noSuchObject);
throw new ApiError(this.meta.errors.noSuchObject);
}
});
}
@ -114,7 +54,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
* URIからUserかNoteを解決する
*/
@bindThis
private async fetchAny(uri: string, me: LocalUser | null | undefined): Promise<SchemaType<typeof meta['res']> | null> {
private async fetchAny(uri: string, me: LocalUser | null | undefined): Promise<SchemaType<Endpoints['ap/show']['defines'][number]['res'], References> | null> {
// ブロックしてたら中断
const fetchedMeta = await this.metaService.fetch();
if (this.utilityService.isBlockedHost(fetchedMeta.blockedHosts, this.utilityService.extractDbHost(uri))) return null;
@ -147,7 +87,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}
@bindThis
private async mergePack(me: LocalUser | null | undefined, user: User | null | undefined, note: Note | null | undefined): Promise<SchemaType<typeof meta.res> | null> {
private async mergePack(me: LocalUser | null | undefined, user: User | null | undefined, note: Note | null | undefined): Promise<SchemaType<Endpoints['ap/show']['defines'][number]['res'], References> | null> {
if (user != null) {
return {
type: 'User',

View File

@ -44,6 +44,7 @@
"@swc/core": "1.3.56",
"@types/json-schema": "^7.0.11",
"eventemitter3": "5.0.1",
"ms": "3.0.0-canary.1",
"reconnecting-websocket": "4.4.0",
"schema-type": "github:misskey-dev/schema-type",
"ts-essentials": "^9.3.2"

View File

@ -1,6 +1,7 @@
import { JSONSchema7 } from 'schema-type';
import type { JSONSchema7 } from 'schema-type';
import { IEndpointMeta } from './endpoints.types';
import { localUsernameSchema, passwordSchema } from './schemas/user';
import ms from 'ms';
export const endpoints = {
//#region admin
@ -2204,6 +2205,84 @@ export const endpoints = {
}],
},
//#endregion
//#region ap
'ap/get': {
tags: ['federation'],
requireCredential: true,
limit: {
duration: ms('1hour'),
max: 30,
},
defines: [{
req: {
type: 'object',
properties: {
uri: { type: 'string' },
},
required: ['uri'],
},
res: {
type: 'object',
},
}],
},
'ap/show': {
tags: ['federation'],
requireCredential: true,
limit: {
duration: ms('1hour'),
max: 30,
},
errors: {
noSuchObject: {
message: 'No such object.',
code: 'NO_SUCH_OBJECT',
id: 'dc94d745-1262-4e63-a17d-fecaa57efc82',
},
},
defines: [{
req: {
type: 'object',
properties: {
uri: { type: 'string' },
},
required: ['uri'],
},
res: {
oneOf: [
{
type: 'object',
properties: {
type: { const: 'User' },
object: {
$ref: 'https://misskey-hub.net/api/schemas/UserDetailedNotMe',
},
},
required: ['type', 'object'],
},
{
type: 'object',
properties: {
type: { const: 'Note' },
object: {
$ref: 'https://misskey-hub.net/api/schemas/Note',
},
},
required: ['type', 'object'],
},
],
},
}],
}
//#endregion
} as const satisfies { [x: string]: IEndpointMeta; };
/**

View File

@ -630,7 +630,7 @@ importers:
version: 29.5.0
schema-type:
specifier: github:misskey-dev/schema-type
version: github.com/misskey-dev/schema-type/65413af4ef676dafb5d06ebc04dce39c74b3a8f9(typescript@5.0.4)
version: github.com/misskey-dev/schema-type/65413af4ef676dafb5d06ebc04dce39c74b3a8f9(typescript@5.1.3)
packages/frontend:
dependencies:
@ -1028,6 +1028,9 @@ importers:
eventemitter3:
specifier: 5.0.1
version: 5.0.1
ms:
specifier: 3.0.0-canary.1
version: 3.0.0-canary.1
reconnecting-websocket:
specifier: 4.4.0
version: 4.4.0
@ -20334,6 +20337,15 @@ packages:
typescript: '>=4.1.0'
dependencies:
typescript: 5.0.4
dev: false
/ts-essentials@9.3.2(typescript@5.1.3):
resolution: {integrity: sha512-JxKJzuWqH1MmH4ZFHtJzGEhkfN3QvVR3C3w+4BIoWeoY68UVVoA2Np/Bca9z0IPSErVCWhv439aT0We4Dks8kQ==}
peerDependencies:
typescript: '>=4.1.0'
dependencies:
typescript: 5.1.3
dev: true
/ts-map@1.0.3:
resolution: {integrity: sha512-vDWbsl26LIcPGmDpoVzjEP6+hvHZkBkLW7JpvwbCv/5IYPJlsbzCVXY3wsCeAxAUeTclNOUZxnLdGh3VBD/J6w==}
@ -20584,7 +20596,6 @@ packages:
resolution: {integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==}
engines: {node: '>=12.20'}
hasBin: true
dev: true
/typescript@5.1.3:
resolution: {integrity: sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==}
@ -21755,6 +21766,20 @@ packages:
tsd: 0.28.1
transitivePeerDependencies:
- typescript
dev: false
github.com/misskey-dev/schema-type/65413af4ef676dafb5d06ebc04dce39c74b3a8f9(typescript@5.1.3):
resolution: {tarball: https://codeload.github.com/misskey-dev/schema-type/tar.gz/65413af4ef676dafb5d06ebc04dce39c74b3a8f9}
id: github.com/misskey-dev/schema-type/65413af4ef676dafb5d06ebc04dce39c74b3a8f9
name: schema-type
version: 1.0.0
dependencies:
'@types/json-schema': 7.0.11
ts-essentials: 9.3.2(typescript@5.1.3)
tsd: 0.28.1
transitivePeerDependencies:
- typescript
dev: true
github.com/misskey-dev/sharp-read-bmp/02d9dc189fa7df0c4bea09330be26741772dac01:
resolution: {tarball: https://codeload.github.com/misskey-dev/sharp-read-bmp/tar.gz/02d9dc189fa7df0c4bea09330be26741772dac01}