2470afaa2e
* wip * Update CHANGELOG.md * wip * wip * wip * Update create.ts * wip * wip * Update CHANGELOG.md * wip * wip * wip * wip * wip * wip * wip * Update CHANGELOG.md * wip * wip * Update delete.ts * Update delete.ts * wip * wip * wip * Update account-info.vue * wip * wip * Update settings.vue * Update user-info.vue * wip * Update show-file.ts * Update show-user.ts * wip * wip * Update delete.ts * wip * wip * Update overview.moderators.vue * Create 1673500412259-Role.js * wip * wip * Update roles.vue * 色 * Update roles.vue * integrate silence * wip * wip
72 lines
2 KiB
TypeScript
72 lines
2 KiB
TypeScript
import ms from 'ms';
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import type { UsersRepository } from '@/models/index.js';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import { NoteDeleteService } from '@/core/NoteDeleteService.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { GetterService } from '@/server/api/GetterService.js';
|
|
import { RoleService } from '@/core/RoleService.js';
|
|
import { ApiError } from '../../error.js';
|
|
|
|
export const meta = {
|
|
tags: ['notes'],
|
|
|
|
requireCredential: true,
|
|
|
|
kind: 'write:notes',
|
|
|
|
limit: {
|
|
duration: ms('1hour'),
|
|
max: 300,
|
|
minInterval: ms('1sec'),
|
|
},
|
|
|
|
errors: {
|
|
noSuchNote: {
|
|
message: 'No such note.',
|
|
code: 'NO_SUCH_NOTE',
|
|
id: '490be23f-8c1f-4796-819f-94cb4f9d1630',
|
|
},
|
|
|
|
accessDenied: {
|
|
message: 'Access denied.',
|
|
code: 'ACCESS_DENIED',
|
|
id: 'fe8d7103-0ea8-4ec3-814d-f8b401dc69e9',
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
noteId: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['noteId'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
constructor(
|
|
@Inject(DI.usersRepository)
|
|
private usersRepository: UsersRepository,
|
|
|
|
private getterService: GetterService,
|
|
private roleService: RoleService,
|
|
private noteDeleteService: NoteDeleteService,
|
|
) {
|
|
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;
|
|
});
|
|
|
|
if (!await this.roleService.isModerator(me) && (note.userId !== me.id)) {
|
|
throw new ApiError(meta.errors.accessDenied);
|
|
}
|
|
|
|
// この操作を行うのが投稿者とは限らない(例えばモデレーター)ため
|
|
await this.noteDeleteService.delete(await this.usersRepository.findOneByOrFail({ id: note.userId }), note);
|
|
});
|
|
}
|
|
}
|