aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/bulk.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/bulk.ts')
-rw-r--r--server/controllers/api/bulk.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/server/controllers/api/bulk.ts b/server/controllers/api/bulk.ts
new file mode 100644
index 000000000..1fe139c92
--- /dev/null
+++ b/server/controllers/api/bulk.ts
@@ -0,0 +1,41 @@
1import * as express from 'express'
2import { asyncMiddleware, authenticate } from '../../middlewares'
3import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk'
4import { VideoCommentModel } from '@server/models/video/video-comment'
5import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
6import { removeComment } from '@server/lib/video-comment'
7
8const bulkRouter = express.Router()
9
10bulkRouter.post('/remove-comments-of',
11 authenticate,
12 asyncMiddleware(bulkRemoveCommentsOfValidator),
13 asyncMiddleware(bulkRemoveCommentsOf)
14)
15
16// ---------------------------------------------------------------------------
17
18export {
19 bulkRouter
20}
21
22// ---------------------------------------------------------------------------
23
24async 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}