From 7f28b7334c488d2a8eaca0ecdb173cb4c0fa6652 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 4 Jun 2023 17:42:10 +0000 Subject: [PATCH] wip --- .../api/endpoints/channels/my-favorites.ts | 30 +-------- .../server/api/endpoints/channels/owned.ts | 33 +-------- .../server/api/endpoints/channels/search.ts | 33 +-------- packages/misskey-js/src/endpoints.ts | 67 +++++++++++++++++++ 4 files changed, 76 insertions(+), 87 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/channels/my-favorites.ts b/packages/backend/src/server/api/endpoints/channels/my-favorites.ts index 60525ed06..d099fb499 100644 --- a/packages/backend/src/server/api/endpoints/channels/my-favorites.ts +++ b/packages/backend/src/server/api/endpoints/channels/my-favorites.ts @@ -5,34 +5,10 @@ import { QueryService } from '@/core/QueryService.js'; import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js'; import { DI } from '@/di-symbols.js'; -export const meta = { - tags: ['channels', 'account'], - - requireCredential: true, - - kind: 'read:channels', - - res: { - type: 'array', - optional: false, nullable: false, - items: { - type: 'object', - optional: false, nullable: false, - ref: 'Channel', - }, - }, -} 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<'channels/my-favorites'> { + name = 'channels/my-favorites' as const; constructor( @Inject(DI.channelFavoritesRepository) private channelFavoritesRepository: ChannelFavoritesRepository, @@ -40,7 +16,7 @@ export default class extends Endpoint { private channelEntityService: ChannelEntityService, private queryService: QueryService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const query = this.channelFavoritesRepository.createQueryBuilder('favorite') .andWhere('favorite.userId = :meId', { meId: me.id }) .leftJoinAndSelect('favorite.channel', 'channel'); diff --git a/packages/backend/src/server/api/endpoints/channels/owned.ts b/packages/backend/src/server/api/endpoints/channels/owned.ts index 8fae972cb..a19728f4f 100644 --- a/packages/backend/src/server/api/endpoints/channels/owned.ts +++ b/packages/backend/src/server/api/endpoints/channels/owned.ts @@ -5,37 +5,10 @@ import { QueryService } from '@/core/QueryService.js'; import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js'; import { DI } from '@/di-symbols.js'; -export const meta = { - tags: ['channels', 'account'], - - requireCredential: true, - - kind: 'read:channels', - - res: { - type: 'array', - optional: false, nullable: false, - items: { - type: 'object', - optional: false, nullable: false, - ref: 'Channel', - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - sinceId: { type: 'string', format: 'misskey:id' }, - untilId: { type: 'string', format: 'misskey:id' }, - limit: { type: 'integer', minimum: 1, maximum: 100, default: 5 }, - }, - required: [], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'channels/owned'> { + name = 'channels/owned' as const; constructor( @Inject(DI.channelsRepository) private channelsRepository: ChannelsRepository, @@ -43,7 +16,7 @@ export default class extends Endpoint { private channelEntityService: ChannelEntityService, private queryService: QueryService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const query = this.queryService.makePaginationQuery(this.channelsRepository.createQueryBuilder('channel'), ps.sinceId, ps.untilId) .andWhere('channel.isArchived = FALSE') .andWhere({ userId: me.id }); diff --git a/packages/backend/src/server/api/endpoints/channels/search.ts b/packages/backend/src/server/api/endpoints/channels/search.ts index a3b40b0bb..67ccd772f 100644 --- a/packages/backend/src/server/api/endpoints/channels/search.ts +++ b/packages/backend/src/server/api/endpoints/channels/search.ts @@ -7,37 +7,10 @@ import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js'; import { DI } from '@/di-symbols.js'; import { sqlLikeEscape } from '@/misc/sql-like-escape.js'; -export const meta = { - tags: ['channels'], - - requireCredential: false, - - res: { - type: 'array', - optional: false, nullable: false, - items: { - type: 'object', - optional: false, nullable: false, - ref: 'Channel', - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - query: { type: 'string' }, - type: { type: 'string', enum: ['nameAndDescription', 'nameOnly'], default: 'nameAndDescription' }, - sinceId: { type: 'string', format: 'misskey:id' }, - untilId: { type: 'string', format: 'misskey:id' }, - limit: { type: 'integer', minimum: 1, maximum: 100, default: 5 }, - }, - required: ['query'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'channels/search'> { + name = 'channels/search' as const; constructor( @Inject(DI.channelsRepository) private channelsRepository: ChannelsRepository, @@ -45,7 +18,7 @@ export default class extends Endpoint { private channelEntityService: ChannelEntityService, private queryService: QueryService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const query = this.queryService.makePaginationQuery(this.channelsRepository.createQueryBuilder('channel'), ps.sinceId, ps.untilId) .andWhere('channel.isArchived = FALSE'); diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index c34ecf1b1..ee03883b6 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -2739,6 +2739,73 @@ export const endpoints = { }, }], }, + 'channels/my-favorites': { + tags: ['channels', 'account'], + + requireCredential: true, + + kind: 'read:channels', + + defines: [{ + req: undefined, + res: { + type: 'array', + items: { + $ref: 'https://misskey-hub.net/api/schemas/Channel', + }, + }, + }], + }, + 'channels/owned': { + tags: ['channels', 'account'], + + requireCredential: true, + + kind: 'read:channels', + + defines: [{ + req: { + type: 'object', + properties: { + sinceId: { type: 'string', format: 'misskey:id' }, + untilId: { type: 'string', format: 'misskey:id' }, + limit: { type: 'integer', minimum: 1, maximum: 100, default: 5 }, + }, + required: [], + }, + res: { + type: 'array', + items: { + $ref: 'https://misskey-hub.net/api/schemas/Channel', + }, + }, + }], + }, + 'channels/search': { + tags: ['channels'], + + requireCredential: false, + + defines: [{ + req: { + type: 'object', + properties: { + query: { type: 'string' }, + type: { type: 'string', enum: ['nameAndDescription', 'nameOnly'], default: 'nameAndDescription' }, + sinceId: { type: 'string', format: 'misskey:id' }, + untilId: { type: 'string', format: 'misskey:id' }, + limit: { type: 'integer', minimum: 1, maximum: 100, default: 5 }, + }, + required: ['query'], + }, + res: { + type: 'array', + items: { + $ref: 'https://misskey-hub.net/api/schemas/Channel', + }, + }, + }], + }, //#endregion } as const satisfies { [x: string]: IEndpointMeta; };