2021-04-26 04:10:45 +02:00
|
|
|
import $ from 'cafy';
|
2021-08-19 14:55:45 +02:00
|
|
|
import define from '../../../define';
|
|
|
|
import { ApiError } from '../../../error';
|
|
|
|
import { GalleryPosts } from '@/models/index';
|
|
|
|
import { ID } from '@/misc/cafy-id';
|
2021-04-26 04:10:45 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['gallery'],
|
|
|
|
|
|
|
|
requireCredential: true as const,
|
|
|
|
|
|
|
|
kind: 'write:gallery',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
postId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchPost: {
|
|
|
|
message: 'No such post.',
|
|
|
|
code: 'NO_SUCH_POST',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: 'ae52f367-4bd7-4ecd-afc6-5672fff427f5',
|
2021-04-26 04:10:45 +02:00
|
|
|
},
|
2021-12-09 15:58:30 +01:00
|
|
|
},
|
2021-04-26 04:10:45 +02:00
|
|
|
};
|
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2021-04-26 04:10:45 +02:00
|
|
|
export default define(meta, async (ps, user) => {
|
|
|
|
const post = await GalleryPosts.findOne({
|
|
|
|
id: ps.postId,
|
|
|
|
userId: user.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (post == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchPost);
|
|
|
|
}
|
|
|
|
|
|
|
|
await GalleryPosts.delete(post.id);
|
|
|
|
});
|