From 41c353e24d4441ff518b645bea79336b5c66bd48 Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 26 May 2023 07:32:15 +0000 Subject: [PATCH] wip --- .../admin/emoji/set-category-bulk.ts | 2 +- .../api/endpoints/admin/emoji/update.ts | 57 +-------- .../admin/federation/delete-all-files.ts | 20 +--- .../refresh-remote-instance-metadata.ts | 20 +--- .../admin/federation/remove-all-following.ts | 20 +--- .../admin/federation/update-instance.ts | 5 +- packages/misskey-js/src/endpoints.ts | 109 ++++++++++++++++++ 7 files changed, 126 insertions(+), 107 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/set-category-bulk.ts b/packages/backend/src/server/api/endpoints/admin/emoji/set-category-bulk.ts index da23c5a57..c571dacf8 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/set-category-bulk.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/set-category-bulk.ts @@ -5,7 +5,7 @@ import { CustomEmojiService } from '@/core/CustomEmojiService.js'; // eslint-disable-next-line import/no-default-export @Injectable() export default class extends Endpoint<'admin/emoji/set-category-bulk'> { - name = 'admin/emoji/set-category-bulk' as const + name = 'admin/emoji/set-category-bulk' as const; constructor( private customEmojiService: CustomEmojiService, ) { diff --git a/packages/backend/src/server/api/endpoints/admin/emoji/update.ts b/packages/backend/src/server/api/endpoints/admin/emoji/update.ts index fb22bdc47..ebcabe824 100644 --- a/packages/backend/src/server/api/endpoints/admin/emoji/update.ts +++ b/packages/backend/src/server/api/endpoints/admin/emoji/update.ts @@ -4,71 +4,22 @@ import { CustomEmojiService } from '@/core/CustomEmojiService.js'; import type { DriveFilesRepository } from '@/models/index.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../../error.js'; - -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireRolePolicy: 'canManageCustomEmojis', - - errors: { - noSuchEmoji: { - message: 'No such emoji.', - code: 'NO_SUCH_EMOJI', - id: '684dec9d-a8c2-4364-9aa8-456c49cb1dc8', - }, - noSuchFile: { - message: 'No such file.', - code: 'NO_SUCH_FILE', - id: '14fb9fd9-0731-4e2f-aeb9-f09e4740333d', - }, - sameNameEmojiExists: { - message: 'Emoji that have same name already exists.', - code: 'SAME_NAME_EMOJI_EXISTS', - id: '7180fe9d-1ee3-bff9-647d-fe9896d2ffb8', - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - id: { type: 'string', format: 'misskey:id' }, - name: { type: 'string', pattern: '^[a-zA-Z0-9_]+$' }, - fileId: { type: 'string', format: 'misskey:id' }, - category: { - type: 'string', - nullable: true, - description: 'Use `null` to reset the category.', - }, - aliases: { type: 'array', items: { - type: 'string', - } }, - license: { type: 'string', nullable: true }, - isSensitive: { type: 'boolean' }, - localOnly: { type: 'boolean' }, - roleIdsThatCanBeUsedThisEmojiAsReaction: { type: 'array', items: { - type: 'string', - } }, - }, - required: ['id', 'name', 'aliases'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/emoji/update'> { + name = 'admin/emoji/update' as const; constructor( @Inject(DI.driveFilesRepository) private driveFilesRepository: DriveFilesRepository, private customEmojiService: CustomEmojiService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { let driveFile; if (ps.fileId) { driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId }); - if (driveFile == null) throw new ApiError(meta.errors.noSuchFile); + if (driveFile == null) throw new ApiError(this.meta.errors.noSuchFile); } await this.customEmojiService.update(ps.id, { diff --git a/packages/backend/src/server/api/endpoints/admin/federation/delete-all-files.ts b/packages/backend/src/server/api/endpoints/admin/federation/delete-all-files.ts index 38fe99b22..0b12b00e6 100644 --- a/packages/backend/src/server/api/endpoints/admin/federation/delete-all-files.ts +++ b/packages/backend/src/server/api/endpoints/admin/federation/delete-all-files.ts @@ -4,31 +4,17 @@ import type { DriveFilesRepository } from '@/models/index.js'; import { DriveService } from '@/core/DriveService.js'; import { DI } from '@/di-symbols.js'; -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireModerator: true, -} as const; - -export const paramDef = { - type: 'object', - properties: { - host: { type: 'string' }, - }, - required: ['host'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/federation/delete-all-files'> { + name = 'admin/federation/delete-all-files' as const; constructor( @Inject(DI.driveFilesRepository) private driveFilesRepository: DriveFilesRepository, private driveService: DriveService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const files = await this.driveFilesRepository.findBy({ userHost: ps.host, }); diff --git a/packages/backend/src/server/api/endpoints/admin/federation/refresh-remote-instance-metadata.ts b/packages/backend/src/server/api/endpoints/admin/federation/refresh-remote-instance-metadata.ts index b7f2858a7..29a4d5730 100644 --- a/packages/backend/src/server/api/endpoints/admin/federation/refresh-remote-instance-metadata.ts +++ b/packages/backend/src/server/api/endpoints/admin/federation/refresh-remote-instance-metadata.ts @@ -5,24 +5,10 @@ import { FetchInstanceMetadataService } from '@/core/FetchInstanceMetadataServic import { UtilityService } from '@/core/UtilityService.js'; import { DI } from '@/di-symbols.js'; -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireModerator: true, -} as const; - -export const paramDef = { - type: 'object', - properties: { - host: { type: 'string' }, - }, - required: ['host'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/federation/refresh-remote-instance-metadata'> { + name = 'admin/federation/refresh-remote-instance-metadata' as const; constructor( @Inject(DI.instancesRepository) private instancesRepository: InstancesRepository, @@ -30,7 +16,7 @@ export default class extends Endpoint { private utilityService: UtilityService, private fetchInstanceMetadataService: FetchInstanceMetadataService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const instance = await this.instancesRepository.findOneBy({ host: this.utilityService.toPuny(ps.host) }); if (instance == null) { diff --git a/packages/backend/src/server/api/endpoints/admin/federation/remove-all-following.ts b/packages/backend/src/server/api/endpoints/admin/federation/remove-all-following.ts index 83f729953..e9c6871fb 100644 --- a/packages/backend/src/server/api/endpoints/admin/federation/remove-all-following.ts +++ b/packages/backend/src/server/api/endpoints/admin/federation/remove-all-following.ts @@ -4,24 +4,10 @@ import type { FollowingsRepository, UsersRepository } from '@/models/index.js'; import { DI } from '@/di-symbols.js'; import { QueueService } from '@/core/QueueService.js'; -export const meta = { - tags: ['admin'], - - requireCredential: true, - requireModerator: true, -} as const; - -export const paramDef = { - type: 'object', - properties: { - host: { type: 'string' }, - }, - required: ['host'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/federation/remove-all-following'> { + name = 'admin/federation/remove-all-following' as const; constructor( @Inject(DI.usersRepository) private usersRepository: UsersRepository, @@ -31,7 +17,7 @@ export default class extends Endpoint { private queueService: QueueService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const followings = await this.followingsRepository.findBy({ followerHost: ps.host, }); diff --git a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts index 4fd74e591..bd1022066 100644 --- a/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts +++ b/packages/backend/src/server/api/endpoints/admin/federation/update-instance.ts @@ -23,7 +23,8 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/federation/update-instance'> { + name = 'admin/federation/update-instance' as const; constructor( @Inject(DI.instancesRepository) private instancesRepository: InstancesRepository, @@ -31,7 +32,7 @@ export default class extends Endpoint { private utilityService: UtilityService, private federatedInstanceService: FederatedInstanceService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const instance = await this.instancesRepository.findOneBy({ host: this.utilityService.toPuny(ps.host) }); if (instance == null) { diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index be495f7c1..bb3cf4ac4 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -748,6 +748,115 @@ export const endpoints = { res: undefined, }], }, + 'admin/emoji/update': { + tags: ['admin'], + + requireCredential: true, + requireRolePolicy: 'canManageCustomEmojis', + + errors: { + noSuchFile: { + message: 'No such file.', + code: 'NO_SUCH_FILE', + id: '14fb9fd9-0731-4e2f-aeb9-f09e4740333d', + }, + }, + + defines: [{ + req: { + type: 'object', + properties: { + id: { type: 'string', format: 'misskey:id' }, + name: { type: 'string', pattern: '^[a-zA-Z0-9_]+$' }, + fileId: { type: 'string', format: 'misskey:id' }, + category: { + type: ['string', 'null'], + description: 'Use `null` to reset the category.', + }, + aliases: { type: 'array', items: { + type: 'string', + } }, + license: { type: ['string', 'null'] }, + isSensitive: { type: 'boolean' }, + localOnly: { type: 'boolean' }, + roleIdsThatCanBeUsedThisEmojiAsReaction: { type: 'array', items: { + type: 'string', + } }, + }, + required: ['id', 'name', 'aliases'], + }, + res: undefined, + }], + }, + 'admin/federation/delete-all-files': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: { + type: 'object', + properties: { + host: { type: 'string' }, + }, + required: ['host'], + }, + res: undefined, + }], + }, + 'admin/federation/refresh-remote-instance-metadata': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: { + type: 'object', + properties: { + host: { type: 'string' }, + }, + required: ['host'], + }, + res: undefined, + }], + }, + 'admin/federation/remove-all-following': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: { + type: 'object', + properties: { + host: { type: 'string' }, + }, + required: ['host'], + }, + res: undefined, + }], + }, + 'admin/federation/update-instance': { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: { + type: 'object', + properties: { + host: { type: 'string' }, + isSuspended: { type: 'boolean' }, + }, + required: ['host', 'isSuspended'], + }, + res: undefined, + }], + }, } as const satisfies { [x: string]: IEndpointMeta; }; export function getEndpointSchema(reqres: 'req' | 'res', key: keyof typeof endpoints) {