1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Video blacklist refractoring

This commit is contained in:
Chocobozzz 2017-10-10 10:02:18 +02:00
parent 769d332177
commit 35bf0c83c8
No known key found for this signature in database
GPG key ID: 583A612D890159BE
33 changed files with 239 additions and 269 deletions

View file

@ -1,22 +1,46 @@
import * as express from 'express'
import { database as db } from '../../../initializers/database'
import { logger } from '../../../helpers'
import { database as db } from '../../../initializers'
import { logger, getFormattedObjects } from '../../../helpers'
import {
authenticate,
ensureIsAdmin,
videosBlacklistValidator
videosBlacklistAddValidator,
videosBlacklistRemoveValidator,
paginationValidator,
blacklistSortValidator,
setBlacklistSort,
setPagination
} from '../../../middlewares'
import { BlacklistedVideoInstance } from '../../../models'
import { BlacklistedVideo } from '../../../../shared'
const blacklistRouter = express.Router()
blacklistRouter.post('/:id/blacklist',
blacklistRouter.post('/:videoId/blacklist',
authenticate,
ensureIsAdmin,
videosBlacklistValidator,
videosBlacklistAddValidator,
addVideoToBlacklist
)
blacklistRouter.get('/blacklist',
authenticate,
ensureIsAdmin,
paginationValidator,
blacklistSortValidator,
setBlacklistSort,
setPagination,
listBlacklist
)
blacklistRouter.delete('/:videoId/blacklist',
authenticate,
ensureIsAdmin,
videosBlacklistRemoveValidator,
removeVideoFromBlacklistController
)
// ---------------------------------------------------------------------------
export {
@ -39,3 +63,23 @@ function addVideoToBlacklist (req: express.Request, res: express.Response, next:
return next(err)
})
}
function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
db.BlacklistedVideo.listForApi(req.query.start, req.query.count, req.query.sort)
.then(resultList => res.json(getFormattedObjects<BlacklistedVideo, BlacklistedVideoInstance>(resultList.data, resultList.total)))
.catch(err => next(err))
}
function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {
const blacklistedVideo = res.locals.blacklistedVideo as BlacklistedVideoInstance
blacklistedVideo.destroy()
.then(() => {
logger.info('Video %s removed from blacklist.', res.locals.video.uuid)
res.sendStatus(204)
})
.catch(err => {
logger.error('Some error while removing video %s from blacklist.', res.locals.video.uuid, err)
next(err)
})
}