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