From c756bae079e02873f6433582ca14a092fec0db27 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Sun, 6 Jun 2021 10:21:06 +0200 Subject: add video upload types, add doc middleware to more routes --- server/controllers/api/videos/index.ts | 23 ++++++++++++++++++---- server/controllers/api/videos/watching.ts | 9 ++++++++- server/middlewares/validators/videos/video-live.ts | 10 ++++++---- server/middlewares/validators/videos/videos.ts | 9 ++++++--- 4 files changed, 39 insertions(+), 12 deletions(-) (limited to 'server') 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) videosRouter.use('/', uploadRouter) videosRouter.use('/', updateRouter) -videosRouter.get('/categories', listVideoCategories) -videosRouter.get('/licences', listVideoLicences) -videosRouter.get('/languages', listVideoLanguages) -videosRouter.get('/privacies', listVideoPrivacies) +videosRouter.get('/categories', + openapiOperationDoc({ operationId: 'getCategories' }), + listVideoCategories +) +videosRouter.get('/licences', + openapiOperationDoc({ operationId: 'getLicences' }), + listVideoLicences +) +videosRouter.get('/languages', + openapiOperationDoc({ operationId: 'getLanguages' }), + listVideoLanguages +) +videosRouter.get('/privacies', + openapiOperationDoc({ operationId: 'getPrivacies' }), + listVideoPrivacies +) videosRouter.get('/', + openapiOperationDoc({ operationId: 'getVideos' }), paginationValidator, videosSortValidator, setDefaultVideosSort, @@ -76,6 +89,7 @@ videosRouter.get('/', ) videosRouter.get('/:id/description', + openapiOperationDoc({ operationId: 'getVideoDesc' }), asyncMiddleware(videosGetValidator), asyncMiddleware(getVideoDescription) ) @@ -91,6 +105,7 @@ videosRouter.get('/:id', asyncMiddleware(getVideo) ) videosRouter.post('/:id/views', + openapiOperationDoc({ operationId: 'addView' }), asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), asyncMiddleware(viewVideo) ) 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 @@ import * as express from 'express' import { UserWatchingVideo } from '../../../../shared' -import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares' +import { + asyncMiddleware, + asyncRetryTransactionMiddleware, + authenticate, + openapiOperationDoc, + videoWatchingValidator +} from '../../../middlewares' import { UserVideoHistoryModel } from '../../../models/user/user-video-history' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const watchingRouter = express.Router() watchingRouter.put('/:videoId/watching', + openapiOperationDoc({ operationId: 'setProgress' }), authenticate, asyncMiddleware(videoWatchingValidator), 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([ return res.fail({ status: HttpStatusCode.FORBIDDEN_403, - message: 'Live is not enabled on this instance' + message: 'Live is not enabled on this instance', + type: ServerErrorCode.LIVE_NOT_ENABLED }) } @@ -81,7 +82,8 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ return res.fail({ status: HttpStatusCode.FORBIDDEN_403, - message: 'Saving live replay is not allowed instance' + message: 'Saving live replay is not enabled on this instance', + type: ServerErrorCode.LIVE_NOT_ALLOWING_REPLAY }) } @@ -116,8 +118,8 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([ return res.fail({ status: HttpStatusCode.FORBIDDEN_403, - type: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED, - message: 'Cannot create this live because the max user lives limit is reached.' + message: 'Cannot create this live because the max user lives limit is reached.', + type: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED }) } } 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 = [ if (isAble === false) { res.fail({ status: HttpStatusCode.PAYLOAD_TOO_LARGE_413, - message: 'The user video quota is exceeded with this video.' + message: 'The user video quota is exceeded with this video.', + type: ServerErrorCode.QUOTA_REACHED }) return } @@ -628,7 +629,8 @@ async function commonVideoChecksPass (parameters: { if (!isVideoFileSizeValid(videoFileSize.toString())) { res.fail({ status: HttpStatusCode.PAYLOAD_TOO_LARGE_413, - message: 'This file is too large. It exceeds the maximum file size authorized.' + message: 'This file is too large. It exceeds the maximum file size authorized.', + type: ServerErrorCode.MAX_FILE_SIZE_REACHED }) return false } @@ -636,7 +638,8 @@ async function commonVideoChecksPass (parameters: { if (await isAbleToUploadVideo(user.id, videoFileSize) === false) { res.fail({ status: HttpStatusCode.PAYLOAD_TOO_LARGE_413, - message: 'The user video quota is exceeded with this video.' + message: 'The user video quota is exceeded with this video.', + type: ServerErrorCode.QUOTA_REACHED }) return false } -- cgit v1.2.3