mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-12-01 21:09:17 -06:00
7226e90fdc
Hooks prefixed by `action:api` now give access the original express req and res. Checkout guide.md for possible usage.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import express from 'express'
|
|
import { removeComment } from '@server/lib/video-comment'
|
|
import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk'
|
|
import { VideoCommentModel } from '@server/models/video/video-comment'
|
|
import { HttpStatusCode } from '@shared/models'
|
|
import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
|
|
import { asyncMiddleware, authenticate } from '../../middlewares'
|
|
|
|
const bulkRouter = express.Router()
|
|
|
|
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
|
|
res.status(HttpStatusCode.NO_CONTENT_204).end()
|
|
|
|
for (const comment of comments) {
|
|
await removeComment(comment, req, res)
|
|
}
|
|
}
|