aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2021-06-06 10:21:06 +0200
committerRigel Kent <sendmemail@rigelk.eu>2021-06-06 10:21:06 +0200
commitc756bae079e02873f6433582ca14a092fec0db27 (patch)
tree2b24e065144fdb11b8b1ef58ef3157530bd6b2d1 /server
parentfc21ef5c62d845576a916414468b3a57370a57b2 (diff)
downloadPeerTube-c756bae079e02873f6433582ca14a092fec0db27.tar.gz
PeerTube-c756bae079e02873f6433582ca14a092fec0db27.tar.zst
PeerTube-c756bae079e02873f6433582ca14a092fec0db27.zip
add video upload types, add doc middleware to more routes
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/index.ts23
-rw-r--r--server/controllers/api/videos/watching.ts9
-rw-r--r--server/middlewares/validators/videos/video-live.ts10
-rw-r--r--server/middlewares/validators/videos/videos.ts9
4 files changed, 39 insertions, 12 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 703051ee2..8c6c44144 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -60,12 +60,25 @@ videosRouter.use('/', liveRouter)
60videosRouter.use('/', uploadRouter) 60videosRouter.use('/', uploadRouter)
61videosRouter.use('/', updateRouter) 61videosRouter.use('/', updateRouter)
62 62
63videosRouter.get('/categories', listVideoCategories) 63videosRouter.get('/categories',
64videosRouter.get('/licences', listVideoLicences) 64 openapiOperationDoc({ operationId: 'getCategories' }),
65videosRouter.get('/languages', listVideoLanguages) 65 listVideoCategories
66videosRouter.get('/privacies', listVideoPrivacies) 66)
67videosRouter.get('/licences',
68 openapiOperationDoc({ operationId: 'getLicences' }),
69 listVideoLicences
70)
71videosRouter.get('/languages',
72 openapiOperationDoc({ operationId: 'getLanguages' }),
73 listVideoLanguages
74)
75videosRouter.get('/privacies',
76 openapiOperationDoc({ operationId: 'getPrivacies' }),
77 listVideoPrivacies
78)
67 79
68videosRouter.get('/', 80videosRouter.get('/',
81 openapiOperationDoc({ operationId: 'getVideos' }),
69 paginationValidator, 82 paginationValidator,
70 videosSortValidator, 83 videosSortValidator,
71 setDefaultVideosSort, 84 setDefaultVideosSort,
@@ -76,6 +89,7 @@ videosRouter.get('/',
76) 89)
77 90
78videosRouter.get('/:id/description', 91videosRouter.get('/:id/description',
92 openapiOperationDoc({ operationId: 'getVideoDesc' }),
79 asyncMiddleware(videosGetValidator), 93 asyncMiddleware(videosGetValidator),
80 asyncMiddleware(getVideoDescription) 94 asyncMiddleware(getVideoDescription)
81) 95)
@@ -91,6 +105,7 @@ videosRouter.get('/:id',
91 asyncMiddleware(getVideo) 105 asyncMiddleware(getVideo)
92) 106)
93videosRouter.post('/:id/views', 107videosRouter.post('/:id/views',
108 openapiOperationDoc({ operationId: 'addView' }),
94 asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), 109 asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')),
95 asyncMiddleware(viewVideo) 110 asyncMiddleware(viewVideo)
96) 111)
diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts
index 08190e583..8b15525aa 100644
--- a/server/controllers/api/videos/watching.ts
+++ b/server/controllers/api/videos/watching.ts
@@ -1,12 +1,19 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserWatchingVideo } from '../../../../shared' 2import { UserWatchingVideo } from '../../../../shared'
3import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares' 3import {
4 asyncMiddleware,
5 asyncRetryTransactionMiddleware,
6 authenticate,
7 openapiOperationDoc,
8 videoWatchingValidator
9} from '../../../middlewares'
4import { UserVideoHistoryModel } from '../../../models/user/user-video-history' 10import { UserVideoHistoryModel } from '../../../models/user/user-video-history'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 11import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6 12
7const watchingRouter = express.Router() 13const watchingRouter = express.Router()
8 14
9watchingRouter.put('/:videoId/watching', 15watchingRouter.put('/:videoId/watching',
16 openapiOperationDoc({ operationId: 'setProgress' }),
10 authenticate, 17 authenticate,
11 asyncMiddleware(videoWatchingValidator), 18 asyncMiddleware(videoWatchingValidator),
12 asyncRetryTransactionMiddleware(userWatchVideo) 19 asyncRetryTransactionMiddleware(userWatchVideo)
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts
index ffc8c47b3..b058ff5c1 100644
--- a/server/middlewares/validators/videos/video-live.ts
+++ b/server/middlewares/validators/videos/video-live.ts
@@ -72,7 +72,8 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
72 72
73 return res.fail({ 73 return res.fail({
74 status: HttpStatusCode.FORBIDDEN_403, 74 status: HttpStatusCode.FORBIDDEN_403,
75 message: 'Live is not enabled on this instance' 75 message: 'Live is not enabled on this instance',
76 type: ServerErrorCode.LIVE_NOT_ENABLED
76 }) 77 })
77 } 78 }
78 79
@@ -81,7 +82,8 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
81 82
82 return res.fail({ 83 return res.fail({
83 status: HttpStatusCode.FORBIDDEN_403, 84 status: HttpStatusCode.FORBIDDEN_403,
84 message: 'Saving live replay is not allowed instance' 85 message: 'Saving live replay is not enabled on this instance',
86 type: ServerErrorCode.LIVE_NOT_ALLOWING_REPLAY
85 }) 87 })
86 } 88 }
87 89
@@ -116,8 +118,8 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
116 118
117 return res.fail({ 119 return res.fail({
118 status: HttpStatusCode.FORBIDDEN_403, 120 status: HttpStatusCode.FORBIDDEN_403,
119 type: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED, 121 message: 'Cannot create this live because the max user lives limit is reached.',
120 message: 'Cannot create this live because the max user lives limit is reached.' 122 type: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED
121 }) 123 })
122 } 124 }
123 } 125 }
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index 52e6c5762..7f278c9f6 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -402,7 +402,8 @@ const videosAcceptChangeOwnershipValidator = [
402 if (isAble === false) { 402 if (isAble === false) {
403 res.fail({ 403 res.fail({
404 status: HttpStatusCode.PAYLOAD_TOO_LARGE_413, 404 status: HttpStatusCode.PAYLOAD_TOO_LARGE_413,
405 message: 'The user video quota is exceeded with this video.' 405 message: 'The user video quota is exceeded with this video.',
406 type: ServerErrorCode.QUOTA_REACHED
406 }) 407 })
407 return 408 return
408 } 409 }
@@ -628,7 +629,8 @@ async function commonVideoChecksPass (parameters: {
628 if (!isVideoFileSizeValid(videoFileSize.toString())) { 629 if (!isVideoFileSizeValid(videoFileSize.toString())) {
629 res.fail({ 630 res.fail({
630 status: HttpStatusCode.PAYLOAD_TOO_LARGE_413, 631 status: HttpStatusCode.PAYLOAD_TOO_LARGE_413,
631 message: 'This file is too large. It exceeds the maximum file size authorized.' 632 message: 'This file is too large. It exceeds the maximum file size authorized.',
633 type: ServerErrorCode.MAX_FILE_SIZE_REACHED
632 }) 634 })
633 return false 635 return false
634 } 636 }
@@ -636,7 +638,8 @@ async function commonVideoChecksPass (parameters: {
636 if (await isAbleToUploadVideo(user.id, videoFileSize) === false) { 638 if (await isAbleToUploadVideo(user.id, videoFileSize) === false) {
637 res.fail({ 639 res.fail({
638 status: HttpStatusCode.PAYLOAD_TOO_LARGE_413, 640 status: HttpStatusCode.PAYLOAD_TOO_LARGE_413,
639 message: 'The user video quota is exceeded with this video.' 641 message: 'The user video quota is exceeded with this video.',
642 type: ServerErrorCode.QUOTA_REACHED
640 }) 643 })
641 return false 644 return false
642 } 645 }