2021-08-27 08:32:44 -04:00
|
|
|
import express from 'express'
|
2023-07-31 08:34:36 -04:00
|
|
|
import { BulkRemoveCommentsOfBody, HttpStatusCode } from '@peertube/peertube-models'
|
|
|
|
import { removeComment } from '@server/lib/video-comment.js'
|
|
|
|
import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk.js'
|
|
|
|
import { VideoCommentModel } from '@server/models/video/video-comment.js'
|
|
|
|
import { apiRateLimiter, asyncMiddleware, authenticate } from '../../middlewares/index.js'
|
2020-05-14 10:56:15 -04:00
|
|
|
|
|
|
|
const bulkRouter = express.Router()
|
|
|
|
|
2023-06-20 08:17:34 -04:00
|
|
|
bulkRouter.use(apiRateLimiter)
|
|
|
|
|
2020-05-14 10:56:15 -04:00
|
|
|
bulkRouter.post('/remove-comments-of',
|
|
|
|
authenticate,
|
|
|
|
asyncMiddleware(bulkRemoveCommentsOfValidator),
|
|
|
|
asyncMiddleware(bulkRemoveCommentsOf)
|
|
|
|
)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
bulkRouter
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
async function bulkRemoveCommentsOf (req: express.Request, res: express.Response) {
|
|
|
|
const account = res.locals.account
|
|
|
|
const body = req.body as BulkRemoveCommentsOfBody
|
|
|
|
const user = res.locals.oauth.token.User
|
|
|
|
|
|
|
|
const filter = body.scope === 'my-videos'
|
|
|
|
? { onVideosOfAccount: user.Account }
|
|
|
|
: {}
|
|
|
|
|
|
|
|
const comments = await VideoCommentModel.listForBulkDelete(account, filter)
|
|
|
|
|
|
|
|
// Don't wait result
|
2021-05-31 19:36:53 -04:00
|
|
|
res.status(HttpStatusCode.NO_CONTENT_204).end()
|
2020-05-14 10:56:15 -04:00
|
|
|
|
|
|
|
for (const comment of comments) {
|
2021-11-24 08:33:14 -05:00
|
|
|
await removeComment(comment, req, res)
|
2020-05-14 10:56:15 -04:00
|
|
|
}
|
|
|
|
}
|