From f651ca4b485dfeaf9f168a5d5e7df936fe802335 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 4 Jun 2023 15:39:43 +0000 Subject: [PATCH] wip --- .../src/server/api/endpoints/app/create.ts | 30 +---- .../src/server/api/endpoints/app/show.ts | 33 +----- packages/misskey-js/src/endpoints.ts | 106 ++++++++++++++---- 3 files changed, 90 insertions(+), 79 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/app/create.ts b/packages/backend/src/server/api/endpoints/app/create.ts index c1d0a9dd7..863d6d7a2 100644 --- a/packages/backend/src/server/api/endpoints/app/create.ts +++ b/packages/backend/src/server/api/endpoints/app/create.ts @@ -7,34 +7,10 @@ import { secureRndstr } from '@/misc/secure-rndstr.js'; import { AppEntityService } from '@/core/entities/AppEntityService.js'; import { DI } from '@/di-symbols.js'; -export const meta = { - tags: ['app'], - - requireCredential: false, - - res: { - type: 'object', - optional: false, nullable: false, - ref: 'App', - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - name: { type: 'string' }, - description: { type: 'string' }, - permission: { type: 'array', uniqueItems: true, items: { - type: 'string', - } }, - callbackUrl: { type: 'string', nullable: true }, - }, - required: ['name', 'description', 'permission'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'app/create'> { + name = 'app/create' as const; constructor( @Inject(DI.appsRepository) private appsRepository: AppsRepository, @@ -42,7 +18,7 @@ export default class extends Endpoint { private appEntityService: AppEntityService, private idService: IdService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { // Generate secret const secret = secureRndstr(32, true); diff --git a/packages/backend/src/server/api/endpoints/app/show.ts b/packages/backend/src/server/api/endpoints/app/show.ts index eaafa8dc1..db515f851 100644 --- a/packages/backend/src/server/api/endpoints/app/show.ts +++ b/packages/backend/src/server/api/endpoints/app/show.ts @@ -5,49 +5,24 @@ import { AppEntityService } from '@/core/entities/AppEntityService.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../error.js'; -export const meta = { - tags: ['app'], - - errors: { - noSuchApp: { - message: 'No such app.', - code: 'NO_SUCH_APP', - id: 'dce83913-2dc6-4093-8a7b-71dbb11718a3', - }, - }, - - res: { - type: 'object', - optional: false, nullable: false, - ref: 'App', - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - appId: { type: 'string', format: 'misskey:id' }, - }, - required: ['appId'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'app/show'> { + name = 'app/show' as const; constructor( @Inject(DI.appsRepository) private appsRepository: AppsRepository, private appEntityService: AppEntityService, ) { - super(meta, paramDef, async (ps, user, token) => { + super(async (ps, user, token) => { const isSecure = user != null && token == null; // Lookup app const ap = await this.appsRepository.findOneBy({ id: ps.appId }); if (ap == null) { - throw new ApiError(meta.errors.noSuchApp); + throw new ApiError(this.meta.errors.noSuchApp); } return await this.appEntityService.pack(ap, user, { diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index 32414981b..6476841d6 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -2145,20 +2145,20 @@ export const endpoints = { }, 'antennas/update': { tags: ['antennas'], - + requireCredential: true, - + prohibitMoved: true, - + kind: 'write:account', - + errors: { noSuchAntenna: { message: 'No such antenna.', code: 'NO_SUCH_ANTENNA', id: '10c673ac-8852-48eb-aa1f-f5b67f069290', }, - + noSuchUserList: { message: 'No such user list.', code: 'NO_SUCH_USER_LIST', @@ -2179,19 +2179,25 @@ export const endpoints = { { type: 'null' }, ], }, - keywords: { type: 'array', items: { + keywords: { + type: 'array', items: { + type: 'array', items: { + type: 'string', + }, + } + }, + excludeKeywords: { + type: 'array', items: { + type: 'array', items: { + type: 'string', + }, + } + }, + users: { type: 'array', items: { type: 'string', - }, - } }, - excludeKeywords: { type: 'array', items: { - type: 'array', items: { - type: 'string', - }, - } }, - users: { type: 'array', items: { - type: 'string', - } }, + } + }, caseSensitive: { type: 'boolean' }, withReplies: { type: 'boolean' }, withFile: { type: 'boolean' }, @@ -2209,14 +2215,14 @@ export const endpoints = { //#region ap 'ap/get': { tags: ['federation'], - + requireCredential: true, - + limit: { duration: ms('1hour'), max: 30, }, - + defines: [{ req: { type: 'object', @@ -2232,14 +2238,14 @@ export const endpoints = { }, 'ap/show': { tags: ['federation'], - + requireCredential: true, - + limit: { duration: ms('1hour'), max: 30, }, - + errors: { noSuchObject: { message: 'No such object.', @@ -2247,7 +2253,7 @@ export const endpoints = { id: 'dc94d745-1262-4e63-a17d-fecaa57efc82', }, }, - + defines: [{ req: { type: 'object', @@ -2281,6 +2287,60 @@ export const endpoints = { ], }, }], + }, + //#endregion + + //#region app + 'app/create': { + tags: ['app'], + + requireCredential: false, + + defines: [{ + req: { + type: 'object', + properties: { + name: { type: 'string' }, + description: { type: 'string' }, + permission: { + type: 'array', + uniqueItems: true, + items: { + type: 'string', + }, + }, + callbackUrl: { type: ['string', 'null'] }, + } as const satisfies Record, + required: ['name', 'description', 'permission'], + }, + res: { + $ref: 'https://misskey-hub.net/api/schemas/App', + }, + }], + }, + 'app/show': { + tags: ['app'], + + errors: { + noSuchApp: { + message: 'No such app.', + code: 'NO_SUCH_APP', + id: 'dce83913-2dc6-4093-8a7b-71dbb11718a3', + }, + }, + + defines: [{ + req: { + type: 'object', + properties: { + appId: { type: 'string', format: 'misskey:id' }, + }, + required: ['appId'], + }, + res: { + $ref: 'https://misskey-hub.net/api/schemas/App', + }, + }], } //#endregion } as const satisfies { [x: string]: IEndpointMeta; };