2023-08-15 02:52:38 +09:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-21 05:33:11 +09:00
|
|
|
import type { GalleryPostsRepository } from '@/models/index.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-02-27 11:07:39 +09:00
|
|
|
import { ApiError } from '../../../error.js';
|
2021-04-26 11:10:45 +09:00
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
|
tags: ['gallery'],
|
|
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2023-07-28 04:21:59 +09:00
|
|
|
requireRolePolicy: 'canDeleteContent',
|
2021-04-26 11:10:45 +09:00
|
|
|
|
|
|
|
|
kind: 'write:gallery',
|
|
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
|
noSuchPost: {
|
|
|
|
|
message: 'No such post.',
|
|
|
|
|
code: 'NO_SUCH_POST',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: 'ae52f367-4bd7-4ecd-afc6-5672fff427f5',
|
2021-04-26 11:10:45 +09:00
|
|
|
},
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2021-04-26 11:10:45 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
postId: { type: 'string', format: 'misskey:id' },
|
|
|
|
|
},
|
|
|
|
|
required: ['postId'],
|
|
|
|
|
} 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(
|
|
|
|
|
@Inject(DI.galleryPostsRepository)
|
|
|
|
|
private galleryPostsRepository: GalleryPostsRepository,
|
|
|
|
|
) {
|
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
|
const post = await this.galleryPostsRepository.findOneBy({
|
|
|
|
|
id: ps.postId,
|
|
|
|
|
userId: me.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (post == null) {
|
|
|
|
|
throw new ApiError(meta.errors.noSuchPost);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await this.galleryPostsRepository.delete(post.id);
|
|
|
|
|
});
|
2021-04-26 11:10:45 +09:00
|
|
|
}
|
2022-09-18 03:27:08 +09:00
|
|
|
}
|