mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Add ability to bulk delete comments
This commit is contained in:
parent
99139e7753
commit
444c0a0e01
15 changed files with 516 additions and 66 deletions
41
server/controllers/api/bulk.ts
Normal file
41
server/controllers/api/bulk.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import * as express from 'express'
|
||||
import { asyncMiddleware, authenticate } from '../../middlewares'
|
||||
import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk'
|
||||
import { VideoCommentModel } from '@server/models/video/video-comment'
|
||||
import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
|
||||
import { removeComment } from '@server/lib/video-comment'
|
||||
|
||||
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.sendStatus(204)
|
||||
|
||||
for (const comment of comments) {
|
||||
await removeComment(comment)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue