2021-08-19 21:55:45 +09:00
|
|
|
import define from '../../../define';
|
2021-11-12 19:47:04 +09:00
|
|
|
import ms from 'ms';
|
2021-08-19 21:55:45 +09:00
|
|
|
import deleteReaction from '@/services/note/reaction/delete';
|
|
|
|
|
import { getNote } from '../../../common/getters';
|
|
|
|
|
import { ApiError } from '../../../error';
|
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-02-19 14:05:32 +09:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2019-02-22 14:02:56 +09:00
|
|
|
const note = await getNote(ps.noteId).catch(e => {
|
2019-02-22 11:46:58 +09:00
|
|
|
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
|
|
|
|
throw e;
|
|
|
|
|
});
|
|
|
|
|
await deleteReaction(user, note).catch(e => {
|
|
|
|
|
if (e.id === '60527ec9-b4cb-4a88-a6bd-32d3ad26817d') throw new ApiError(meta.errors.notReacted);
|
|
|
|
|
throw e;
|
|
|
|
|
});
|
|
|
|
|
});
|