2020-05-14 10:56:15 -04:00
|
|
|
import * as express from 'express'
|
2021-07-16 08:27:30 -04:00
|
|
|
import { removeComment } from '@server/lib/video-comment'
|
2020-05-14 10:56:15 -04:00
|
|
|
import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk'
|
|
|
|
import { VideoCommentModel } from '@server/models/video/video-comment'
|
2021-07-16 04:42:24 -04:00
|
|
|
import { HttpStatusCode } from '@shared/models'
|
2021-07-16 08:27:30 -04:00
|
|
|
import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
|
|
|
|
import { asyncMiddleware, authenticate } from '../../middlewares'
|
2020-05-14 10:56:15 -04:00
|
|
|
|
|
|
|
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
|
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) {
|
|
|
|
await removeComment(comment)
|
|
|
|
}
|
|
|
|
}
|