2021-11-12 19:47:04 +09:00
|
|
|
import ms from 'ms';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
|
import { GetterService } from '@/server/api/common/GetterService.js';
|
|
|
|
|
import { ReactionService } from '@/core/ReactionService.js';
|
2022-02-27 11:07:39 +09:00
|
|
|
import { ApiError } from '../../../error.js';
|
2016-12-29 07:49:51 +09:00
|
|
|
|
2018-07-17 04:36:44 +09:00
|
|
|
export const meta = {
|
2019-02-23 11:20:58 +09:00
|
|
|
tags: ['reactions', 'notes'],
|
|
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2018-07-17 04:36:44 +09:00
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
kind: 'write:reactions',
|
2018-11-02 03:32:24 +09:00
|
|
|
|
2018-12-26 23:05:47 +09:00
|
|
|
limit: {
|
|
|
|
|
duration: ms('1hour'),
|
2019-03-18 00:03:57 +09:00
|
|
|
max: 60,
|
2021-12-09 23:58:30 +09:00
|
|
|
minInterval: ms('3sec'),
|
2018-12-26 23:05:47 +09:00
|
|
|
},
|
|
|
|
|
|
2019-02-22 11:46:58 +09:00
|
|
|
errors: {
|
|
|
|
|
noSuchNote: {
|
|
|
|
|
message: 'No such note.',
|
|
|
|
|
code: 'NO_SUCH_NOTE',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: '764d9fce-f9f2-4a0e-92b1-6ceac9a7ad37',
|
2019-02-22 11:46:58 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
notReacted: {
|
|
|
|
|
message: 'You are not reacting to that note.',
|
|
|
|
|
code: 'NOT_REACTED',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: '92f4426d-4196-4125-aa5b-02943e2ec8fc',
|
2019-02-22 11:46:58 +09:00
|
|
|
},
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2018-07-17 04:36:44 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
noteId: { type: 'string', format: 'misskey:id' },
|
|
|
|
|
},
|
|
|
|
|
required: ['noteId'],
|
|
|
|
|
} as const;
|
|
|
|
|
|
2022-01-03 02:12:50 +09:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
|
constructor(
|
|
|
|
|
private getterService: GetterService,
|
|
|
|
|
private reactionService: ReactionService,
|
|
|
|
|
) {
|
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
|
const note = await this.getterService.getNote(ps.noteId).catch(err => {
|
|
|
|
|
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
|
|
|
|
throw err;
|
|
|
|
|
});
|
|
|
|
|
await this.reactionService.delete(me, note).catch(err => {
|
|
|
|
|
if (err.id === '60527ec9-b4cb-4a88-a6bd-32d3ad26817d') throw new ApiError(meta.errors.notReacted);
|
|
|
|
|
throw err;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|