47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { deleteNotes } from '@/services/note/delete.js';
|
|
import define from '@/server/api/define.js';
|
|
import { Notes } from '@/models/index.js';
|
|
import { ApiError } from '@/server/api/error.js';
|
|
|
|
export const meta = {
|
|
tags: ['notes'],
|
|
|
|
description: 'Deletes multiple notes. This will be processed in a more performant way than deleting the notes with individual API calls.',
|
|
|
|
requireCredential: true,
|
|
requireAdmin: true,
|
|
|
|
kind: 'write:notes',
|
|
|
|
// Since only admins can use this API endpoint, a rate limit would not
|
|
// apply to them anyway so the rate limit for deletions is not added here.
|
|
|
|
errors: ['NO_SUCH_NOTE'],
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
noteIds: {
|
|
type: 'array',
|
|
uniqueItems: true,
|
|
minItems: 1,
|
|
items: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
},
|
|
required: ['noteIds'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default define(meta, paramDef, async (ps, user) => {
|
|
try {
|
|
const notes = await Promise.all(
|
|
ps.noteIds.map(noteId => Notes.findOneByOrFail({ id: noteId }))
|
|
);
|
|
|
|
await deleteNotes(notes);
|
|
} catch {
|
|
throw new ApiError('NO_SUCH_NOTE');
|
|
}
|
|
});
|