PeerTube/server/controllers/api/bulk.ts

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-08-27 14:32:44 +02:00
import express from 'express'
2021-07-16 14:27:30 +02:00
import { removeComment } from '@server/lib/video-comment'
2020-05-14 16:56:15 +02:00
import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk'
import { VideoCommentModel } from '@server/models/video/video-comment'
2021-07-16 10:42:24 +02:00
import { HttpStatusCode } from '@shared/models'
2021-07-16 14:27:30 +02:00
import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
2023-06-20 14:17:34 +02:00
import { apiRateLimiter, asyncMiddleware, authenticate } from '../../middlewares'
2020-05-14 16:56:15 +02:00
const bulkRouter = express.Router()
2023-06-20 14:17:34 +02:00
bulkRouter.use(apiRateLimiter)
2020-05-14 16:56:15 +02: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
res.status(HttpStatusCode.NO_CONTENT_204).end()
2020-05-14 16:56:15 +02:00
for (const comment of comments) {
await removeComment(comment, req, res)
2020-05-14 16:56:15 +02:00
}
}