ActivityPub-federated video streaming platform using P2P directly in your web browser
refactor docMiddleware to support operationId-only form
Rigel Kent1c627fd8d2e6
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.tsindex 7671f099eb..703051ee2b 100644--- a/server/controllers/api/videos/index.ts+++ b/server/controllers/api/videos/index.ts@@ -2,7 +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 { openapiOperationDoc } from '@server/middlewares/doc'import { getServerActor } from '@server/models/application/application'import { MVideoAccountLight } from '@server/types/models'import { VideosCommonQuery } from '../../../../shared'@@ -84,7 +84,7 @@ videosRouter.get('/:id/metadata/:videoFileId',asyncMiddleware(getVideoFileMetadata))videosRouter.get('/:id',- docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo'),+ openapiOperationDoc({ operationId: 'getVideo' }),optionalAuthenticate,asyncMiddleware(videosCustomGetValidator('only-video-with-rights')),asyncMiddleware(checkVideoFollowConstraints),@@ -96,7 +96,7 @@ videosRouter.post('/:id/views',)videosRouter.delete('/:id',- docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo'),+ openapiOperationDoc({ operationId: 'delVideo' }),authenticate,asyncMiddleware(videosRemoveValidator),asyncRetryTransactionMiddleware(removeVideo)diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.tsindex 09e584d309..8affe71c68 100644--- a/server/controllers/api/videos/update.ts+++ b/server/controllers/api/videos/update.ts@@ -20,7 +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'+import { openapiOperationDoc } from '@server/middlewares/doc'const lTags = loggerTagsFactory('api', 'video')const auditLogger = auditLoggerFactory('videos')@@ -36,7 +36,7 @@ const reqVideoFileUpdate = createReqFiles()updateRouter.put('/:id',- docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/putVideo'),+ openapiOperationDoc({ operationId: 'putVideo' }),authenticate,reqVideoFileUpdate,asyncMiddleware(videosUpdateValidator),diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.tsindex 93a68f759d..783cc329ac 100644--- a/server/controllers/api/videos/upload.ts+++ b/server/controllers/api/videos/upload.ts@@ -6,7 +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 { openapiOperationDoc } from '@server/middlewares/doc'import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models'import { uploadx } from '@uploadx/core'import { VideoCreate, VideoState } from '../../../../shared'@@ -61,7 +61,7 @@ const reqVideoFileAddResumable = createReqFiles()uploadRouter.post('/upload',- docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy'),+ openapiOperationDoc({ operationId: 'uploadLegacy' }),authenticate,reqVideoFileAdd,asyncMiddleware(videosAddLegacyValidator),@@ -69,7 +69,7 @@ uploadRouter.post('/upload',)uploadRouter.post('/upload-resumable',- docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumableInit'),+ openapiOperationDoc({ operationId: 'uploadResumableInit' }),authenticate,reqVideoFileAddResumable,asyncMiddleware(videosAddResumableInitValidator),@@ -82,7 +82,7 @@ uploadRouter.delete('/upload-resumable',)uploadRouter.put('/upload-resumable',- docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumable'),+ openapiOperationDoc({ operationId: 'uploadResumable' }),authenticate,uploadxMiddleware, // uploadx doesn't use call next() before the file upload completesasyncMiddleware(videosAddResumableValidator),diff --git a/server/middlewares/doc.ts b/server/middlewares/doc.tsindex aa852cd77f..3db85c68d9 100644--- a/server/middlewares/doc.ts+++ b/server/middlewares/doc.ts@@ -1,13 +1,16 @@import * as express from 'express'-function docMiddleware (docUrl: string) {+function openapiOperationDoc (options: {+ url?: string+ operationId?: string+}) {return (req: express.Request, res: express.Response, next: express.NextFunction) => {- res.locals.docUrl = docUrl+ res.locals.docUrl = options.url || 'https://docs.joinpeertube.org/api-rest-reference.html#operation/' + options.operationIdif (next) return next()}}export {- docMiddleware+ openapiOperationDoc}