From e030bfb59dd5ee65f20a64686ec9b22ca39f70ae Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 2 Jun 2021 18:15:41 +0200 Subject: Refactor server errors handler --- server/controllers/api/videos/index.ts | 3 +++ server/controllers/api/videos/update.ts | 2 ++ server/controllers/api/videos/upload.ts | 4 ++++ 3 files changed, 9 insertions(+) (limited to 'server/controllers/api/videos') diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index db23e5630..7671f099e 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts @@ -2,6 +2,7 @@ import * as express from 'express' import toInt from 'validator/lib/toInt' import { doJSONRequest } from '@server/helpers/requests' import { LiveManager } from '@server/lib/live-manager' +import { docMiddleware } from '@server/middlewares/doc' import { getServerActor } from '@server/models/application/application' import { MVideoAccountLight } from '@server/types/models' import { VideosCommonQuery } from '../../../../shared' @@ -83,6 +84,7 @@ videosRouter.get('/:id/metadata/:videoFileId', asyncMiddleware(getVideoFileMetadata) ) videosRouter.get('/:id', + docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo'), optionalAuthenticate, asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), asyncMiddleware(checkVideoFollowConstraints), @@ -94,6 +96,7 @@ videosRouter.post('/:id/views', ) videosRouter.delete('/:id', + docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo'), authenticate, asyncMiddleware(videosRemoveValidator), asyncRetryTransactionMiddleware(removeVideo) diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts index 2450abd0e..09e584d30 100644 --- a/server/controllers/api/videos/update.ts +++ b/server/controllers/api/videos/update.ts @@ -20,6 +20,7 @@ import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videosUpdateValidator } from '../../../middlewares' import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' import { VideoModel } from '../../../models/video/video' +import { docMiddleware } from '@server/middlewares/doc' const lTags = loggerTagsFactory('api', 'video') const auditLogger = auditLoggerFactory('videos') @@ -35,6 +36,7 @@ const reqVideoFileUpdate = createReqFiles( ) updateRouter.put('/:id', + docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/putVideo'), authenticate, reqVideoFileUpdate, asyncMiddleware(videosUpdateValidator), diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts index c33d7fcb9..93a68f759 100644 --- a/server/controllers/api/videos/upload.ts +++ b/server/controllers/api/videos/upload.ts @@ -6,6 +6,7 @@ import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' import { addOptimizeOrMergeAudioJob, buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' +import { docMiddleware } from '@server/middlewares/doc' import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' import { uploadx } from '@uploadx/core' import { VideoCreate, VideoState } from '../../../../shared' @@ -60,6 +61,7 @@ const reqVideoFileAddResumable = createReqFiles( ) uploadRouter.post('/upload', + docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy'), authenticate, reqVideoFileAdd, asyncMiddleware(videosAddLegacyValidator), @@ -67,6 +69,7 @@ uploadRouter.post('/upload', ) uploadRouter.post('/upload-resumable', + docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumableInit'), authenticate, reqVideoFileAddResumable, asyncMiddleware(videosAddResumableInitValidator), @@ -79,6 +82,7 @@ uploadRouter.delete('/upload-resumable', ) uploadRouter.put('/upload-resumable', + docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumable'), authenticate, uploadxMiddleware, // uploadx doesn't use call next() before the file upload completes asyncMiddleware(videosAddResumableValidator), -- cgit v1.2.3