]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/videos/blacklist.ts
Fix tag display on video watch
[github/Chocobozzz/PeerTube.git] / server / controllers / api / videos / blacklist.ts
CommitLineData
4d4e5cd4 1import * as express from 'express'
d33242b0 2
35bf0c83
C
3import { database as db } from '../../../initializers'
4import { logger, getFormattedObjects } from '../../../helpers'
65fcc311
C
5import {
6 authenticate,
7 ensureIsAdmin,
35bf0c83
C
8 videosBlacklistAddValidator,
9 videosBlacklistRemoveValidator,
10 paginationValidator,
11 blacklistSortValidator,
12 setBlacklistSort,
eb080476
C
13 setPagination,
14 asyncMiddleware
65fcc311 15} from '../../../middlewares'
35bf0c83
C
16import { BlacklistedVideoInstance } from '../../../models'
17import { BlacklistedVideo } from '../../../../shared'
65fcc311
C
18
19const blacklistRouter = express.Router()
20
35bf0c83 21blacklistRouter.post('/:videoId/blacklist',
65fcc311
C
22 authenticate,
23 ensureIsAdmin,
35bf0c83 24 videosBlacklistAddValidator,
eb080476 25 asyncMiddleware(addVideoToBlacklist)
d33242b0
C
26)
27
35bf0c83
C
28blacklistRouter.get('/blacklist',
29 authenticate,
30 ensureIsAdmin,
31 paginationValidator,
32 blacklistSortValidator,
33 setBlacklistSort,
34 setPagination,
eb080476 35 asyncMiddleware(listBlacklist)
35bf0c83
C
36)
37
38blacklistRouter.delete('/:videoId/blacklist',
39 authenticate,
40 ensureIsAdmin,
41 videosBlacklistRemoveValidator,
eb080476 42 asyncMiddleware(removeVideoFromBlacklistController)
35bf0c83
C
43)
44
d33242b0
C
45// ---------------------------------------------------------------------------
46
65fcc311
C
47export {
48 blacklistRouter
49}
d33242b0
C
50
51// ---------------------------------------------------------------------------
52
eb080476 53async function addVideoToBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
d33242b0
C
54 const videoInstance = res.locals.video
55
56 const toCreate = {
57 videoId: videoInstance.id
58 }
59
eb080476
C
60 await db.BlacklistedVideo.create(toCreate)
61 return res.type('json').status(204).end()
d33242b0 62}
35bf0c83 63
eb080476
C
64async function listBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) {
65 const resultList = await db.BlacklistedVideo.listForApi(req.query.start, req.query.count, req.query.sort)
66
67 return res.json(getFormattedObjects<BlacklistedVideo, BlacklistedVideoInstance>(resultList.data, resultList.total))
35bf0c83
C
68}
69
eb080476 70async function removeVideoFromBlacklistController (req: express.Request, res: express.Response, next: express.NextFunction) {
35bf0c83
C
71 const blacklistedVideo = res.locals.blacklistedVideo as BlacklistedVideoInstance
72
eb080476
C
73 try {
74 await blacklistedVideo.destroy()
75
76 logger.info('Video %s removed from blacklist.', res.locals.video.uuid)
77
78 return res.sendStatus(204)
79 } catch (err) {
80 logger.error('Some error while removing video %s from blacklist.', res.locals.video.uuid, err)
81 throw err
82 }
35bf0c83 83}