ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1.3 KiB

  1. import express from 'express'
  2. import { BulkRemoveCommentsOfBody, HttpStatusCode } from '@peertube/peertube-models'
  3. import { removeComment } from '@server/lib/video-comment.js'
  4. import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk.js'
  5. import { VideoCommentModel } from '@server/models/video/video-comment.js'
  6. import { apiRateLimiter, asyncMiddleware, authenticate } from '../../middlewares/index.js'
  7. const bulkRouter = express.Router()
  8. bulkRouter.use(apiRateLimiter)
  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.status(HttpStatusCode.NO_CONTENT_204).end()
  29. for (const comment of comments) {
  30. await removeComment(comment, req, res)
  31. }
  32. }