bulk.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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'
  8. const bulkRouter = express.Router()
  9. bulkRouter.post('/remove-comments-of',
  10. authenticate,
  11. asyncMiddleware(bulkRemoveCommentsOfValidator),
  12. asyncMiddleware(bulkRemoveCommentsOf)
  13. )
  14. // ---------------------------------------------------------------------------
  15. export {
  16. bulkRouter
  17. }
  18. // ---------------------------------------------------------------------------
  19. async function bulkRemoveCommentsOf (req: express.Request, res: express.Response) {
  20. const account = res.locals.account
  21. const body = req.body as BulkRemoveCommentsOfBody
  22. const user = res.locals.oauth.token.User
  23. const filter = body.scope === 'my-videos'
  24. ? { onVideosOfAccount: user.Account }
  25. : {}
  26. const comments = await VideoCommentModel.listForBulkDelete(account, filter)
  27. // Don't wait result
  28. res.sendStatus(HttpStatusCode.NO_CONTENT_204)
  29. for (const comment of comments) {
  30. await removeComment(comment)
  31. }
  32. }