diff --git a/packages/backend/src/server/api/endpoints/admin/queue/promote.ts b/packages/backend/src/server/api/endpoints/admin/queue/promote.ts index 4e57e6613e..46d2a22959 100644 --- a/packages/backend/src/server/api/endpoints/admin/queue/promote.ts +++ b/packages/backend/src/server/api/endpoints/admin/queue/promote.ts @@ -3,29 +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: { - type: { type: 'string', enum: ['deliver', 'inbox'] }, - }, - required: ['type'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/queue/promote'> { + name = 'admin/queue/promote' as const; constructor( private moderationLogService: ModerationLogService, private queueService: QueueService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { let delayedQueues; switch (ps.type) { diff --git a/packages/backend/src/server/api/endpoints/admin/queue/stats.ts b/packages/backend/src/server/api/endpoints/admin/queue/stats.ts index 7f3732c970..e381a6926b 100644 --- a/packages/backend/src/server/api/endpoints/admin/queue/stats.ts +++ b/packages/backend/src/server/api/endpoints/admin/queue/stats.ts @@ -2,45 +2,10 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, SystemQueue, WebhookDeliverQueue } from '@/core/QueueModule.js'; -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireModerator: true, - - res: { - type: 'object', - optional: false, nullable: false, - properties: { - deliver: { - optional: false, nullable: false, - ref: 'QueueCount', - }, - inbox: { - optional: false, nullable: false, - ref: 'QueueCount', - }, - db: { - optional: false, nullable: false, - ref: 'QueueCount', - }, - objectStorage: { - optional: false, nullable: false, - ref: 'QueueCount', - }, - }, - }, -} 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/stats'> { + name = 'admin/queue/stats' as const; constructor( @Inject('queue:system') public systemQueue: SystemQueue, @Inject('queue:endedPollNotification') public endedPollNotificationQueue: EndedPollNotificationQueue, @@ -50,7 +15,7 @@ export default class extends Endpoint { @Inject('queue:objectStorage') public objectStorageQueue: ObjectStorageQueue, @Inject('queue:webhookDeliver') public webhookDeliverQueue: WebhookDeliverQueue, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const deliverJobCounts = await this.deliverQueue.getJobCounts(); const inboxJobCounts = await this.inboxQueue.getJobCounts(); const dbJobCounts = await this.dbQueue.getJobCounts(); diff --git a/packages/backend/src/server/api/endpoints/admin/relays/add.ts b/packages/backend/src/server/api/endpoints/admin/relays/add.ts index f12738bd3a..55f2de7ec2 100644 --- a/packages/backend/src/server/api/endpoints/admin/relays/add.ts +++ b/packages/backend/src/server/api/endpoints/admin/relays/add.ts @@ -4,48 +4,6 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import { RelayService } from '@/core/RelayService.js'; import { ApiError } from '../../../error.js'; -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireModerator: true, - - errors: { - invalidUrl: { - message: 'Invalid URL', - code: 'INVALID_URL', - id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c', - }, - }, - - res: { - type: 'object', - optional: false, nullable: false, - properties: { - id: { - type: 'string', - optional: false, nullable: false, - format: 'id', - }, - inbox: { - type: 'string', - optional: false, nullable: false, - format: 'url', - }, - status: { - type: 'string', - optional: false, nullable: false, - default: 'requesting', - enum: [ - 'requesting', - 'accepted', - 'rejected', - ], - }, - }, - }, -} as const; - export const paramDef = { type: 'object', properties: { @@ -56,15 +14,16 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/relays/add'> { + name = 'admin/relays/add' as const; constructor( private relayService: RelayService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { try { if (new URL(ps.inbox).protocol !== 'https:') throw 'https only'; } catch { - throw new ApiError(meta.errors.invalidUrl); + throw new ApiError(this.meta.errors.invalidUrl); } return await this.relayService.addRelay(ps.inbox); diff --git a/packages/backend/src/server/api/endpoints/admin/relays/list.ts b/packages/backend/src/server/api/endpoints/admin/relays/list.ts index 910c90e78e..7e9d0f0581 100644 --- a/packages/backend/src/server/api/endpoints/admin/relays/list.ts +++ b/packages/backend/src/server/api/endpoints/admin/relays/list.ts @@ -2,57 +2,14 @@ import { Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { RelayService } from '@/core/RelayService.js'; -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireModerator: true, - - res: { - type: 'array', - optional: false, nullable: false, - items: { - type: 'object', - optional: false, nullable: false, - properties: { - id: { - type: 'string', - optional: false, nullable: false, - format: 'id', - }, - inbox: { - type: 'string', - optional: false, nullable: false, - format: 'url', - }, - status: { - type: 'string', - optional: false, nullable: false, - default: 'requesting', - enum: [ - 'requesting', - 'accepted', - 'rejected', - ], - }, - }, - }, - }, -} 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/relays/list'> { + name = 'admin/relays/list' as const; constructor( private relayService: RelayService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { return await this.relayService.listRelay(); }); } diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index ad713d7f32..01709bea9a 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -960,6 +960,86 @@ export const endpoints = { }, }], }, + 'admin/queue/promote': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: { + type: 'object', + properties: { + type: { type: 'string', enum: ['deliver', 'inbox'] }, + }, + required: ['type'], + }, + res: undefined, + }], + }, + 'admin/queue/stats': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: undefined, + res: { + type: 'object', + properties: { + deliver: { $ref: 'https://misskey-hub.net/api/schemas/QueueCount' }, + inbox: { $ref: 'https://misskey-hub.net/api/schemas/QueueCount' }, + db: { $ref: 'https://misskey-hub.net/api/schemas/QueueCount' }, + objectStorage: { $ref: 'https://misskey-hub.net/api/schemas/QueueCount' }, + }, + required: ['deliver', 'inbox', 'db', 'objectStorage'], + } + }], + }, + 'admin/relays/add': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + errors: { + invalidUrl: { + message: 'Invalid URL', + code: 'INVALID_URL', + id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c', + }, + }, + + defines: [{ + req: { + type: 'object', + properties: { + inbox: { type: 'string' }, + }, + required: ['inbox'], + }, + res: { + $ref: 'https://misskey-hub.net/api/schemas/Relay', + }, + }], + }, + 'admin/relays/list': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: undefined, + res: { + type: 'array', + items: { + $ref: 'https://misskey-hub.net/api/schemas/Relay', + }, + }, + }], + } } as const satisfies { [x: string]: IEndpointMeta; }; /** diff --git a/packages/misskey-js/src/entities.ts b/packages/misskey-js/src/entities.ts index 44e795ea00..4f8a2fa6ec 100644 --- a/packages/misskey-js/src/entities.ts +++ b/packages/misskey-js/src/entities.ts @@ -38,6 +38,7 @@ export type Clip = Packed<'Clip'>; export type Channel = Packed<'Channel'>; export type Following = Packed<'Following'>; export type Blocking = Packed<'Blocking'>; +export type Relay = Packed<'Relay'>; export type LiteInstanceMetadata = { maintainerName: string | null; diff --git a/packages/misskey-js/src/schemas.ts b/packages/misskey-js/src/schemas.ts index 147cc6b7a5..8671c80806 100644 --- a/packages/misskey-js/src/schemas.ts +++ b/packages/misskey-js/src/schemas.ts @@ -35,6 +35,7 @@ import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from './schemas/em import { packedFlashSchema } from './schemas/flash.js'; import { packedAdSchema } from './schemas/ad.js'; import { packedAnnouncementSchema } from './schemas/announcement.js'; +import { packedRelaySchema } from './schemas/relay.js'; import { Error, ApiError } from './schemas/error.js'; import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type'; @@ -75,6 +76,7 @@ export const refs = { Flash: packedFlashSchema, Ad: packedAdSchema, Announcement: packedAnnouncementSchema, + Relay: packedRelaySchema, Error: Error, ApiError: ApiError, diff --git a/packages/misskey-js/src/schemas/relay.ts b/packages/misskey-js/src/schemas/relay.ts new file mode 100644 index 0000000000..e7bfb9cff3 --- /dev/null +++ b/packages/misskey-js/src/schemas/relay.ts @@ -0,0 +1,31 @@ +import type { JSONSchema7Definition } from 'schema-type'; + +export const packedRelaySchema = { + $id: 'https://misskey-hub.net/api/schemas/Relay', + + type: 'object', + properties: { + id: { + type: 'string', + format: 'id', + }, + inbox: { + type: 'string', + format: 'url', + }, + status: { + type: 'string', + default: 'requesting', + enum: [ + 'requesting', + 'accepted', + 'rejected', + ], + }, + }, + required: [ + 'id', + 'inbox', + 'status' + ], +} as const satisfies JSONSchema7Definition; diff --git a/packages/misskey-js/test-d/schemas.ts b/packages/misskey-js/test-d/schemas.ts index c586611d43..62bdec6614 100644 --- a/packages/misskey-js/test-d/schemas.ts +++ b/packages/misskey-js/test-d/schemas.ts @@ -97,6 +97,9 @@ describe('schemas', () => { test('ad', () => { type Ad = Packed<'Ad'>; }); + test('relay', () => { + type Relay = Packed<'Relay'>; + }); test('error', () => { type Error = Packed<'Error'>; type ApiError = Packed<'ApiError'>;