]>
Commit | Line | Data |
---|---|---|
444c0a0e C |
1 | import * as express from 'express' |
2 | import { asyncMiddleware, authenticate } from '../../middlewares' | |
3 | import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk' | |
4 | import { VideoCommentModel } from '@server/models/video/video-comment' | |
444c0a0e | 5 | import { removeComment } from '@server/lib/video-comment' |
2d53be02 RK |
6 | import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' |
7 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | |
444c0a0e C |
8 | |
9 | const bulkRouter = express.Router() | |
10 | ||
11 | bulkRouter.post('/remove-comments-of', | |
12 | authenticate, | |
13 | asyncMiddleware(bulkRemoveCommentsOfValidator), | |
14 | asyncMiddleware(bulkRemoveCommentsOf) | |
15 | ) | |
16 | ||
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | export { | |
20 | bulkRouter | |
21 | } | |
22 | ||
23 | // --------------------------------------------------------------------------- | |
24 | ||
25 | async function bulkRemoveCommentsOf (req: express.Request, res: express.Response) { | |
26 | const account = res.locals.account | |
27 | const body = req.body as BulkRemoveCommentsOfBody | |
28 | const user = res.locals.oauth.token.User | |
29 | ||
30 | const filter = body.scope === 'my-videos' | |
31 | ? { onVideosOfAccount: user.Account } | |
32 | : {} | |
33 | ||
34 | const comments = await VideoCommentModel.listForBulkDelete(account, filter) | |
35 | ||
36 | // Don't wait result | |
2d53be02 | 37 | res.sendStatus(HttpStatusCode.NO_CONTENT_204) |
444c0a0e C |
38 | |
39 | for (const comment of comments) { | |
40 | await removeComment(comment) | |
41 | } | |
42 | } |