diff options
Diffstat (limited to 'server/controllers/api/videos/blacklist.ts')
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts deleted file mode 100644 index 4103bb063..000000000 --- a/server/controllers/api/videos/blacklist.ts +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { blacklistVideo, unblacklistVideo } from '@server/lib/video-blacklist' | ||
3 | import { HttpStatusCode, UserRight, VideoBlacklistCreate } from '@shared/models' | ||
4 | import { logger } from '../../../helpers/logger' | ||
5 | import { getFormattedObjects } from '../../../helpers/utils' | ||
6 | import { sequelizeTypescript } from '../../../initializers/database' | ||
7 | import { | ||
8 | asyncMiddleware, | ||
9 | authenticate, | ||
10 | blacklistSortValidator, | ||
11 | ensureUserHasRight, | ||
12 | openapiOperationDoc, | ||
13 | paginationValidator, | ||
14 | setBlacklistSort, | ||
15 | setDefaultPagination, | ||
16 | videosBlacklistAddValidator, | ||
17 | videosBlacklistFiltersValidator, | ||
18 | videosBlacklistRemoveValidator, | ||
19 | videosBlacklistUpdateValidator | ||
20 | } from '../../../middlewares' | ||
21 | import { VideoBlacklistModel } from '../../../models/video/video-blacklist' | ||
22 | |||
23 | const blacklistRouter = express.Router() | ||
24 | |||
25 | blacklistRouter.post('/:videoId/blacklist', | ||
26 | openapiOperationDoc({ operationId: 'addVideoBlock' }), | ||
27 | authenticate, | ||
28 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), | ||
29 | asyncMiddleware(videosBlacklistAddValidator), | ||
30 | asyncMiddleware(addVideoToBlacklistController) | ||
31 | ) | ||
32 | |||
33 | blacklistRouter.get('/blacklist', | ||
34 | openapiOperationDoc({ operationId: 'getVideoBlocks' }), | ||
35 | authenticate, | ||
36 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), | ||
37 | paginationValidator, | ||
38 | blacklistSortValidator, | ||
39 | setBlacklistSort, | ||
40 | setDefaultPagination, | ||
41 | videosBlacklistFiltersValidator, | ||
42 | asyncMiddleware(listBlacklist) | ||
43 | ) | ||
44 | |||
45 | blacklistRouter.put('/:videoId/blacklist', | ||
46 | authenticate, | ||
47 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), | ||
48 | asyncMiddleware(videosBlacklistUpdateValidator), | ||
49 | asyncMiddleware(updateVideoBlacklistController) | ||
50 | ) | ||
51 | |||
52 | blacklistRouter.delete('/:videoId/blacklist', | ||
53 | openapiOperationDoc({ operationId: 'delVideoBlock' }), | ||
54 | authenticate, | ||
55 | ensureUserHasRight(UserRight.MANAGE_VIDEO_BLACKLIST), | ||
56 | asyncMiddleware(videosBlacklistRemoveValidator), | ||
57 | asyncMiddleware(removeVideoFromBlacklistController) | ||
58 | ) | ||
59 | |||
60 | // --------------------------------------------------------------------------- | ||
61 | |||
62 | export { | ||
63 | blacklistRouter | ||
64 | } | ||
65 | |||
66 | // --------------------------------------------------------------------------- | ||
67 | |||
68 | async function addVideoToBlacklistController (req: express.Request, res: express.Response) { | ||
69 | const videoInstance = res.locals.videoAll | ||
70 | const body: VideoBlacklistCreate = req.body | ||
71 | |||
72 | await blacklistVideo(videoInstance, body) | ||
73 | |||
74 | logger.info('Video %s blacklisted.', videoInstance.uuid) | ||
75 | |||
76 | return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() | ||
77 | } | ||
78 | |||
79 | async function updateVideoBlacklistController (req: express.Request, res: express.Response) { | ||
80 | const videoBlacklist = res.locals.videoBlacklist | ||
81 | |||
82 | if (req.body.reason !== undefined) videoBlacklist.reason = req.body.reason | ||
83 | |||
84 | await sequelizeTypescript.transaction(t => { | ||
85 | return videoBlacklist.save({ transaction: t }) | ||
86 | }) | ||
87 | |||
88 | return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() | ||
89 | } | ||
90 | |||
91 | async function listBlacklist (req: express.Request, res: express.Response) { | ||
92 | const resultList = await VideoBlacklistModel.listForApi({ | ||
93 | start: req.query.start, | ||
94 | count: req.query.count, | ||
95 | sort: req.query.sort, | ||
96 | search: req.query.search, | ||
97 | type: req.query.type | ||
98 | }) | ||
99 | |||
100 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | ||
101 | } | ||
102 | |||
103 | async function removeVideoFromBlacklistController (req: express.Request, res: express.Response) { | ||
104 | const videoBlacklist = res.locals.videoBlacklist | ||
105 | const video = res.locals.videoAll | ||
106 | |||
107 | await unblacklistVideo(videoBlacklist, video) | ||
108 | |||
109 | logger.info('Video %s removed from blacklist.', video.uuid) | ||
110 | |||
111 | return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end() | ||
112 | } | ||