From a57df6f2ca75058394c554f3e6f9daf0fa6d512a Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 26 May 2023 07:39:13 +0000 Subject: [PATCH] wip --- .../api/endpoints/admin/promo/create.ts | 39 ++-------- .../server/api/endpoints/admin/queue/clear.ts | 18 +---- .../endpoints/admin/queue/deliver-delayed.ts | 5 +- packages/misskey-js/src/endpoints.ts | 73 +++++++++++++++++++ 4 files changed, 84 insertions(+), 51 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/admin/promo/create.ts b/packages/backend/src/server/api/endpoints/admin/promo/create.ts index bee1ffbae..a20bb28fd 100644 --- a/packages/backend/src/server/api/endpoints/admin/promo/create.ts +++ b/packages/backend/src/server/api/endpoints/admin/promo/create.ts @@ -5,55 +5,26 @@ import { GetterService } from '@/server/api/GetterService.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../../error.js'; -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireModerator: true, - - errors: { - noSuchNote: { - message: 'No such note.', - code: 'NO_SUCH_NOTE', - id: 'ee449fbe-af2a-453b-9cae-cf2fe7c895fc', - }, - - alreadyPromoted: { - message: 'The note has already promoted.', - code: 'ALREADY_PROMOTED', - id: 'ae427aa2-7a41-484f-a18c-2c1104051604', - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - noteId: { type: 'string', format: 'misskey:id' }, - expiresAt: { type: 'integer' }, - }, - required: ['noteId', 'expiresAt'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/promo/create'> { + name = 'admin/promo/create' as const; constructor( @Inject(DI.promoNotesRepository) private promoNotesRepository: PromoNotesRepository, private getterService: GetterService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const note = await this.getterService.getNote(ps.noteId).catch(e => { - if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); + if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(this.meta.errors.noSuchNote); throw e; }); const exist = await this.promoNotesRepository.findOneBy({ noteId: note.id }); if (exist != null) { - throw new ApiError(meta.errors.alreadyPromoted); + throw new ApiError(this.meta.errors.alreadyPromoted); } await this.promoNotesRepository.insert({ diff --git a/packages/backend/src/server/api/endpoints/admin/queue/clear.ts b/packages/backend/src/server/api/endpoints/admin/queue/clear.ts index 099e2ff22..be2f5e6c7 100644 --- a/packages/backend/src/server/api/endpoints/admin/queue/clear.ts +++ b/packages/backend/src/server/api/endpoints/admin/queue/clear.ts @@ -3,27 +3,15 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import { ModerationLogService } from '@/core/ModerationLogService.js'; import { QueueService } from '@/core/QueueService.js'; -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireModerator: true, -} as const; - -export const paramDef = { - type: 'object', - properties: {}, - required: [], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/queue/clear'> { + name = 'admin/queue/clear' as const; constructor( private moderationLogService: ModerationLogService, private queueService: QueueService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { this.queueService.destroy(); this.moderationLogService.insertModerationLog(me, 'clearQueue'); diff --git a/packages/backend/src/server/api/endpoints/admin/queue/deliver-delayed.ts b/packages/backend/src/server/api/endpoints/admin/queue/deliver-delayed.ts index 9442bda5e..8000335a7 100644 --- a/packages/backend/src/server/api/endpoints/admin/queue/deliver-delayed.ts +++ b/packages/backend/src/server/api/endpoints/admin/queue/deliver-delayed.ts @@ -41,11 +41,12 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/queue/deliver-delayed'> { + name = 'admin/queue/deliver-delayed' as const; constructor( @Inject('queue:deliver') public deliverQueue: DeliverQueue, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const jobs = await this.deliverQueue.getJobs(['delayed']); const res = [] as [string, number][]; diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index bb3cf4ac4..8fb5273de 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -857,6 +857,79 @@ export const endpoints = { res: undefined, }], }, + 'admin/promo/create': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + errors: { + noSuchNote: { + message: 'No such note.', + code: 'NO_SUCH_NOTE', + id: 'ee449fbe-af2a-453b-9cae-cf2fe7c895fc', + }, + + alreadyPromoted: { + message: 'The note has already promoted.', + code: 'ALREADY_PROMOTED', + id: 'ae427aa2-7a41-484f-a18c-2c1104051604', + }, + }, + + defines: [{ + req: { + type: 'object', + properties: { + noteId: { type: 'string', format: 'misskey:id' }, + expiresAt: { type: 'integer' }, + }, + required: ['noteId', 'expiresAt'], + }, + res: undefined, + }], + }, + 'admin/queue/clear': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: undefined, + res: undefined, + }], + }, + 'admin/queue/deliver-delayed': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: undefined, + res: { + type: 'array', + items: { + type: 'array', + items: { + anyOf: [ + { + type: 'string', + }, + { + type: 'number', + }, + ], + }, + }, + examples: [[ + 'example.com', + 12, + ]], + }, + }], + }, } as const satisfies { [x: string]: IEndpointMeta; }; export function getEndpointSchema(reqres: 'req' | 'res', key: keyof typeof endpoints) {