1
0
Fork 0

refactor docMiddleware to support operationId-only form

This commit is contained in:
Rigel Kent 2021-06-04 08:57:07 +02:00
parent b96d21b744
commit 1c627fd8d2
No known key found for this signature in database
GPG Key ID: 5E53E96A494E452F
4 changed files with 15 additions and 12 deletions

View File

@ -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)

View File

@ -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),

View File

@ -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 completes
asyncMiddleware(videosAddResumableValidator),

View File

@ -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.operationId
if (next) return next()
}
}
export {
docMiddleware
openapiOperationDoc
}