mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Video blacklist refractoring
This commit is contained in:
parent
769d332177
commit
35bf0c83c8
33 changed files with 239 additions and 269 deletions
|
@ -1,60 +0,0 @@
|
|||
import * as express from 'express'
|
||||
|
||||
import { database } from '../../initializers'
|
||||
import { getFormattedObjects } from '../../helpers'
|
||||
import { BlacklistedVideo } from '../../../shared'
|
||||
import { BlacklistedVideoInstance } from '../../models'
|
||||
|
||||
import {
|
||||
removeVideoFromBlacklist
|
||||
} from '../../lib'
|
||||
import {
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
paginationValidator,
|
||||
blacklistSortValidator,
|
||||
setBlacklistSort,
|
||||
setPagination,
|
||||
blacklistRemoveValidator
|
||||
} from '../../middlewares'
|
||||
|
||||
const blacklistRouter = express.Router()
|
||||
|
||||
blacklistRouter.get('/',
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
paginationValidator,
|
||||
blacklistSortValidator,
|
||||
setBlacklistSort,
|
||||
setPagination,
|
||||
listBlacklist
|
||||
)
|
||||
|
||||
blacklistRouter.delete('/:id',
|
||||
authenticate,
|
||||
ensureIsAdmin,
|
||||
blacklistRemoveValidator,
|
||||
removeVideoFromBlacklistController
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
blacklistRouter
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
|
||||
database.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 entry = res.locals.blacklistEntryToRemove as BlacklistedVideoInstance
|
||||
|
||||
removeVideoFromBlacklist(entry)
|
||||
.then(() => res.sendStatus(204))
|
||||
.catch(err => next(err))
|
||||
}
|
|
@ -9,7 +9,6 @@ import { remoteRouter } from './remote'
|
|||
import { requestSchedulerRouter } from './request-schedulers'
|
||||
import { usersRouter } from './users'
|
||||
import { videosRouter } from './videos'
|
||||
import { blacklistRouter } from './blacklist'
|
||||
|
||||
const apiRouter = express.Router()
|
||||
|
||||
|
@ -20,7 +19,6 @@ apiRouter.use('/remote', remoteRouter)
|
|||
apiRouter.use('/request-schedulers', requestSchedulerRouter)
|
||||
apiRouter.use('/users', usersRouter)
|
||||
apiRouter.use('/videos', videosRouter)
|
||||
apiRouter.use('/blacklist', blacklistRouter)
|
||||
apiRouter.use('/ping', pong)
|
||||
apiRouter.use('/*', badRequest)
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue