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 { removeComment } from '@server/lib/video-comment'
6 import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
7 import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
9 const bulkRouter = express.Router()
11 bulkRouter.post('/remove-comments-of',
13 asyncMiddleware(bulkRemoveCommentsOfValidator),
14 asyncMiddleware(bulkRemoveCommentsOf)
17 // ---------------------------------------------------------------------------
23 // ---------------------------------------------------------------------------
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
30 const filter = body.scope === 'my-videos'
31 ? { onVideosOfAccount: user.Account }
34 const comments = await VideoCommentModel.listForBulkDelete(account, filter)
37 res.sendStatus(HttpStatusCode.NO_CONTENT_204)
39 for (const comment of comments) {
40 await removeComment(comment)