From ae3ce71bb218ee3f6179f71de8246c5b75039e00 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 3 Jul 2023 05:59:23 +0000 Subject: [PATCH] flash --- .../server/api/endpoints/flash/my-likes.ts | 43 +---- .../src/server/api/endpoints/flash/my.ts | 33 +--- .../src/server/api/endpoints/flash/show.ts | 35 +--- .../src/server/api/endpoints/flash/unlike.ts | 41 +---- .../src/server/api/endpoints/flash/update.ts | 52 +----- packages/misskey-js/src/endpoints.ts | 164 ++++++++++++++++++ 6 files changed, 184 insertions(+), 184 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/flash/my-likes.ts b/packages/backend/src/server/api/endpoints/flash/my-likes.ts index f7716ea74..7f03287d8 100644 --- a/packages/backend/src/server/api/endpoints/flash/my-likes.ts +++ b/packages/backend/src/server/api/endpoints/flash/my-likes.ts @@ -5,47 +5,10 @@ import { QueryService } from '@/core/QueryService.js'; import { FlashLikeEntityService } from '@/core/entities/FlashLikeEntityService.js'; import { DI } from '@/di-symbols.js'; -export const meta = { - tags: ['account', 'flash'], - - requireCredential: true, - - kind: 'read:flash-likes', - - res: { - type: 'array', - optional: false, nullable: false, - items: { - type: 'object', - properties: { - id: { - type: 'string', - optional: false, nullable: false, - format: 'id', - }, - flash: { - type: 'object', - optional: false, nullable: false, - ref: 'Flash', - }, - }, - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, - sinceId: { type: 'string', format: 'misskey:id' }, - untilId: { type: 'string', format: 'misskey:id' }, - }, - required: [], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'flash/my-likes'> { + name = 'flash/my-likes' as const; constructor( @Inject(DI.flashLikesRepository) private flashLikesRepository: FlashLikesRepository, @@ -53,7 +16,7 @@ export default class extends Endpoint { private flashLikeEntityService: FlashLikeEntityService, private queryService: QueryService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const query = this.queryService.makePaginationQuery(this.flashLikesRepository.createQueryBuilder('like'), ps.sinceId, ps.untilId) .andWhere('like.userId = :meId', { meId: me.id }) .leftJoinAndSelect('like.flash', 'flash'); diff --git a/packages/backend/src/server/api/endpoints/flash/my.ts b/packages/backend/src/server/api/endpoints/flash/my.ts index baed7f000..a474d082c 100644 --- a/packages/backend/src/server/api/endpoints/flash/my.ts +++ b/packages/backend/src/server/api/endpoints/flash/my.ts @@ -5,37 +5,10 @@ import { QueryService } from '@/core/QueryService.js'; import { FlashEntityService } from '@/core/entities/FlashEntityService.js'; import { DI } from '@/di-symbols.js'; -export const meta = { - tags: ['account', 'flash'], - - requireCredential: true, - - kind: 'read:flash', - - res: { - type: 'array', - optional: false, nullable: false, - items: { - type: 'object', - optional: false, nullable: false, - ref: 'Flash', - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, - sinceId: { type: 'string', format: 'misskey:id' }, - untilId: { type: 'string', format: 'misskey:id' }, - }, - required: [], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'flash/my'> { + name = 'flash/my' as const; constructor( @Inject(DI.flashsRepository) private flashsRepository: FlashsRepository, @@ -43,7 +16,7 @@ export default class extends Endpoint { private flashEntityService: FlashEntityService, private queryService: QueryService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const query = this.queryService.makePaginationQuery(this.flashsRepository.createQueryBuilder('flash'), ps.sinceId, ps.untilId) .andWhere('flash.userId = :meId', { meId: me.id }); diff --git a/packages/backend/src/server/api/endpoints/flash/show.ts b/packages/backend/src/server/api/endpoints/flash/show.ts index 14720a8c8..a17223332 100644 --- a/packages/backend/src/server/api/endpoints/flash/show.ts +++ b/packages/backend/src/server/api/endpoints/flash/show.ts @@ -5,37 +5,10 @@ import { FlashEntityService } from '@/core/entities/FlashEntityService.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../error.js'; -export const meta = { - tags: ['flashs'], - - requireCredential: false, - - res: { - type: 'object', - optional: false, nullable: false, - ref: 'Flash', - }, - - errors: { - noSuchFlash: { - message: 'No such flash.', - code: 'NO_SUCH_FLASH', - id: 'f0d34a1a-d29a-401d-90ba-1982122b5630', - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - flashId: { type: 'string', format: 'misskey:id' }, - }, - required: ['flashId'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'flash/show'> { + name = 'flash/show' as const; constructor( @Inject(DI.usersRepository) private usersRepository: UsersRepository, @@ -45,11 +18,11 @@ export default class extends Endpoint { private flashEntityService: FlashEntityService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const flash = await this.flashsRepository.findOneBy({ id: ps.flashId }); if (flash == null) { - throw new ApiError(meta.errors.noSuchFlash); + throw new ApiError(this.meta.errors.noSuchFlash); } return await this.flashEntityService.pack(flash, me); diff --git a/packages/backend/src/server/api/endpoints/flash/unlike.ts b/packages/backend/src/server/api/endpoints/flash/unlike.ts index 696512b06..dd0a31684 100644 --- a/packages/backend/src/server/api/endpoints/flash/unlike.ts +++ b/packages/backend/src/server/api/endpoints/flash/unlike.ts @@ -4,41 +4,10 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../error.js'; -export const meta = { - tags: ['flash'], - - requireCredential: true, - - prohibitMoved: true, - - kind: 'write:flash-likes', - - errors: { - noSuchFlash: { - message: 'No such flash.', - code: 'NO_SUCH_FLASH', - id: 'afe8424a-a69e-432d-a5f2-2f0740c62410', - }, - - notLiked: { - message: 'You have not liked that flash.', - code: 'NOT_LIKED', - id: '755f25a7-9871-4f65-9f34-51eaad9ae0ac', - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - flashId: { type: 'string', format: 'misskey:id' }, - }, - required: ['flashId'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'flash/unlike'> { + name = 'flash/unlike' as const; constructor( @Inject(DI.flashsRepository) private flashsRepository: FlashsRepository, @@ -46,10 +15,10 @@ export default class extends Endpoint { @Inject(DI.flashLikesRepository) private flashLikesRepository: FlashLikesRepository, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const flash = await this.flashsRepository.findOneBy({ id: ps.flashId }); if (flash == null) { - throw new ApiError(meta.errors.noSuchFlash); + throw new ApiError(this.meta.errors.noSuchFlash); } const exist = await this.flashLikesRepository.findOneBy({ @@ -58,7 +27,7 @@ export default class extends Endpoint { }); if (exist == null) { - throw new ApiError(meta.errors.notLiked); + throw new ApiError(this.meta.errors.notLiked); } // Delete like diff --git a/packages/backend/src/server/api/endpoints/flash/update.ts b/packages/backend/src/server/api/endpoints/flash/update.ts index 78dfd4a06..8055cf278 100644 --- a/packages/backend/src/server/api/endpoints/flash/update.ts +++ b/packages/backend/src/server/api/endpoints/flash/update.ts @@ -5,52 +5,10 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../error.js'; -export const meta = { - tags: ['flash'], - - requireCredential: true, - - prohibitMoved: true, - - kind: 'write:flash', - - limit: { - duration: ms('1hour'), - max: 300, - }, - - errors: { - noSuchFlash: { - message: 'No such flash.', - code: 'NO_SUCH_FLASH', - id: '611e13d2-309e-419a-a5e4-e0422da39b02', - }, - - accessDenied: { - message: 'Access denied.', - code: 'ACCESS_DENIED', - id: '08e60c88-5948-478e-a132-02ec701d67b2', - }, - }, -} as const; - -export const paramDef = { - type: 'object', - properties: { - flashId: { type: 'string', format: 'misskey:id' }, - title: { type: 'string' }, - summary: { type: 'string' }, - script: { type: 'string' }, - permissions: { type: 'array', items: { - type: 'string', - } }, - }, - required: ['flashId', 'title', 'summary', 'script', 'permissions'], -} as const; - // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'flash/update'> { + name = 'flash/update' as const; constructor( @Inject(DI.flashsRepository) private flashsRepository: FlashsRepository, @@ -58,13 +16,13 @@ export default class extends Endpoint { @Inject(DI.driveFilesRepository) private driveFilesRepository: DriveFilesRepository, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const flash = await this.flashsRepository.findOneBy({ id: ps.flashId }); if (flash == null) { - throw new ApiError(meta.errors.noSuchFlash); + throw new ApiError(this.meta.errors.noSuchFlash); } if (flash.userId !== me.id) { - throw new ApiError(meta.errors.accessDenied); + throw new ApiError(this.meta.errors.accessDenied); } await this.flashsRepository.update(flash.id, { diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index 46a077575..edc4a90ca 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -4537,6 +4537,170 @@ export const endpoints = { res: undefined, }] }, + 'flash/my-likes': { + tags: ['account', 'flash'], + + requireCredential: true, + + kind: 'read:flash-likes', + + defines: [{ + req: { + type: 'object', + properties: { + limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, + sinceId: { type: 'string', format: 'misskey:id' }, + untilId: { type: 'string', format: 'misskey:id' }, + }, + required: [], + }, + res: { + type: 'array', + items: { + type: 'object', + properties: { + id: { + $ref: 'https://misskey-hub.net/api/schemas/Id', + }, + flash: { + $ref: 'https://misskey-hub.net/api/schemas/Flash', + }, + }, + required: ['id', 'flash'], + }, + }, + }], + }, + 'flash/my': { + tags: ['account', 'flash'], + + requireCredential: true, + + kind: 'read:flash', + + defines: [{ + req: { + type: 'object', + properties: { + limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, + sinceId: { type: 'string', format: 'misskey:id' }, + untilId: { type: 'string', format: 'misskey:id' }, + }, + required: [], + }, + res: { + type: 'array', + items: { + $ref: 'https://misskey-hub.net/api/schemas/Flash', + }, + }, + }], + }, + 'flash/show': { + tags: ['flashs'], + + requireCredential: false, + + errors: { + noSuchFlash: { + message: 'No such flash.', + code: 'NO_SUCH_FLASH', + id: 'f0d34a1a-d29a-401d-90ba-1982122b5630', + }, + }, + + defines: [{ + req: { + type: 'object', + properties: { + flashId: { type: 'string', format: 'misskey:id' }, + }, + required: ['flashId'], + }, + res: { + $ref: 'https://misskey-hub.net/api/schemas/Flash', + }, + }] + }, + 'flash/unlike': { + tags: ['flash'], + + requireCredential: true, + + prohibitMoved: true, + + kind: 'write:flash-likes', + + errors: { + noSuchFlash: { + message: 'No such flash.', + code: 'NO_SUCH_FLASH', + id: 'afe8424a-a69e-432d-a5f2-2f0740c62410', + }, + + notLiked: { + message: 'You have not liked that flash.', + code: 'NOT_LIKED', + id: '755f25a7-9871-4f65-9f34-51eaad9ae0ac', + }, + }, + + defines: [{ + req: { + type: 'object', + properties: { + flashId: { type: 'string', format: 'misskey:id' }, + }, + required: ['flashId'], + }, + res: undefined, + }] + }, + 'flash/update': { + tags: ['flash'], + + requireCredential: true, + + prohibitMoved: true, + + kind: 'write:flash', + + limit: { + duration: ms('1hour'), + max: 300, + }, + + errors: { + noSuchFlash: { + message: 'No such flash.', + code: 'NO_SUCH_FLASH', + id: '611e13d2-309e-419a-a5e4-e0422da39b02', + }, + + accessDenied: { + message: 'Access denied.', + code: 'ACCESS_DENIED', + id: '08e60c88-5948-478e-a132-02ec701d67b2', + }, + }, + + defines: [{ + req: { + type: 'object', + properties: { + flashId: { type: 'string', format: 'misskey:id' }, + title: { type: 'string' }, + summary: { type: 'string' }, + script: { type: 'string' }, + permissions: { type: 'array', items: { + type: 'string', + } }, + }, + required: ['flashId', 'title', 'summary', 'script', 'permissions'], + }, + res: undefined, + }] + }, //#endregion } as const satisfies { [x: string]: IEndpointMeta; };