2020-05-14 09:56:15 -05:00
|
|
|
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 { removeComment } from '@server/lib/video-comment'
|
2020-12-07 07:32:36 -06:00
|
|
|
import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
|
|
|
|
import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
|
2020-05-14 09:56:15 -05: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
|
2020-12-07 07:32:36 -06:00
|
|
|
res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
2020-05-14 09:56:15 -05:00
|
|
|
|
|
|
|
for (const comment of comments) {
|
|
|
|
await removeComment(comment)
|
|
|
|
}
|
|
|
|
}
|