diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2021-06-04 08:57:07 +0200 |
---|---|---|
committer | Rigel Kent <sendmemail@rigelk.eu> | 2021-06-04 09:21:46 +0200 |
commit | 1c627fd8d2e60d4d790353886006485343d70084 (patch) | |
tree | 384fcd80a018eab2ace2a340d028b23359c07dc7 | |
parent | b96d21b744f3b0714636bd43e7f39fb33c3adb73 (diff) | |
download | PeerTube-1c627fd8d2e60d4d790353886006485343d70084.tar.gz PeerTube-1c627fd8d2e60d4d790353886006485343d70084.tar.zst PeerTube-1c627fd8d2e60d4d790353886006485343d70084.zip |
refactor docMiddleware to support operationId-only form
-rw-r--r-- | server/controllers/api/videos/index.ts | 6 | ||||
-rw-r--r-- | server/controllers/api/videos/update.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/videos/upload.ts | 8 | ||||
-rw-r--r-- | server/middlewares/doc.ts | 9 |
4 files changed, 15 insertions, 12 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 7671f099e..703051ee2 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -2,7 +2,7 @@ import * as express from 'express' | |||
2 | import toInt from 'validator/lib/toInt' | 2 | import toInt from 'validator/lib/toInt' |
3 | import { doJSONRequest } from '@server/helpers/requests' | 3 | import { doJSONRequest } from '@server/helpers/requests' |
4 | import { LiveManager } from '@server/lib/live-manager' | 4 | import { LiveManager } from '@server/lib/live-manager' |
5 | import { docMiddleware } from '@server/middlewares/doc' | 5 | import { openapiOperationDoc } from '@server/middlewares/doc' |
6 | import { getServerActor } from '@server/models/application/application' | 6 | import { getServerActor } from '@server/models/application/application' |
7 | import { MVideoAccountLight } from '@server/types/models' | 7 | import { MVideoAccountLight } from '@server/types/models' |
8 | import { VideosCommonQuery } from '../../../../shared' | 8 | import { VideosCommonQuery } from '../../../../shared' |
@@ -84,7 +84,7 @@ videosRouter.get('/:id/metadata/:videoFileId', | |||
84 | asyncMiddleware(getVideoFileMetadata) | 84 | asyncMiddleware(getVideoFileMetadata) |
85 | ) | 85 | ) |
86 | videosRouter.get('/:id', | 86 | videosRouter.get('/:id', |
87 | docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo'), | 87 | openapiOperationDoc({ operationId: 'getVideo' }), |
88 | optionalAuthenticate, | 88 | optionalAuthenticate, |
89 | asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), | 89 | asyncMiddleware(videosCustomGetValidator('only-video-with-rights')), |
90 | asyncMiddleware(checkVideoFollowConstraints), | 90 | asyncMiddleware(checkVideoFollowConstraints), |
@@ -96,7 +96,7 @@ videosRouter.post('/:id/views', | |||
96 | ) | 96 | ) |
97 | 97 | ||
98 | videosRouter.delete('/:id', | 98 | videosRouter.delete('/:id', |
99 | docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo'), | 99 | openapiOperationDoc({ operationId: 'delVideo' }), |
100 | authenticate, | 100 | authenticate, |
101 | asyncMiddleware(videosRemoveValidator), | 101 | asyncMiddleware(videosRemoveValidator), |
102 | asyncRetryTransactionMiddleware(removeVideo) | 102 | asyncRetryTransactionMiddleware(removeVideo) |
diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts index 09e584d30..8affe71c6 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' | |||
20 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videosUpdateValidator } from '../../../middlewares' | 20 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videosUpdateValidator } from '../../../middlewares' |
21 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 21 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
22 | import { VideoModel } from '../../../models/video/video' | 22 | import { VideoModel } from '../../../models/video/video' |
23 | import { docMiddleware } from '@server/middlewares/doc' | 23 | import { openapiOperationDoc } from '@server/middlewares/doc' |
24 | 24 | ||
25 | const lTags = loggerTagsFactory('api', 'video') | 25 | const lTags = loggerTagsFactory('api', 'video') |
26 | const auditLogger = auditLoggerFactory('videos') | 26 | const auditLogger = auditLoggerFactory('videos') |
@@ -36,7 +36,7 @@ const reqVideoFileUpdate = createReqFiles( | |||
36 | ) | 36 | ) |
37 | 37 | ||
38 | updateRouter.put('/:id', | 38 | updateRouter.put('/:id', |
39 | docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/putVideo'), | 39 | openapiOperationDoc({ operationId: 'putVideo' }), |
40 | authenticate, | 40 | authenticate, |
41 | reqVideoFileUpdate, | 41 | reqVideoFileUpdate, |
42 | asyncMiddleware(videosUpdateValidator), | 42 | asyncMiddleware(videosUpdateValidator), |
diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts index 93a68f759..783cc329a 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' | |||
6 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' | 6 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' |
7 | import { addOptimizeOrMergeAudioJob, buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' | 7 | import { addOptimizeOrMergeAudioJob, buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' |
8 | import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' | 8 | import { generateVideoFilename, getVideoFilePath } from '@server/lib/video-paths' |
9 | import { docMiddleware } from '@server/middlewares/doc' | 9 | import { openapiOperationDoc } from '@server/middlewares/doc' |
10 | import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' | 10 | import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' |
11 | import { uploadx } from '@uploadx/core' | 11 | import { uploadx } from '@uploadx/core' |
12 | import { VideoCreate, VideoState } from '../../../../shared' | 12 | import { VideoCreate, VideoState } from '../../../../shared' |
@@ -61,7 +61,7 @@ const reqVideoFileAddResumable = createReqFiles( | |||
61 | ) | 61 | ) |
62 | 62 | ||
63 | uploadRouter.post('/upload', | 63 | uploadRouter.post('/upload', |
64 | docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy'), | 64 | openapiOperationDoc({ operationId: 'uploadLegacy' }), |
65 | authenticate, | 65 | authenticate, |
66 | reqVideoFileAdd, | 66 | reqVideoFileAdd, |
67 | asyncMiddleware(videosAddLegacyValidator), | 67 | asyncMiddleware(videosAddLegacyValidator), |
@@ -69,7 +69,7 @@ uploadRouter.post('/upload', | |||
69 | ) | 69 | ) |
70 | 70 | ||
71 | uploadRouter.post('/upload-resumable', | 71 | uploadRouter.post('/upload-resumable', |
72 | docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumableInit'), | 72 | openapiOperationDoc({ operationId: 'uploadResumableInit' }), |
73 | authenticate, | 73 | authenticate, |
74 | reqVideoFileAddResumable, | 74 | reqVideoFileAddResumable, |
75 | asyncMiddleware(videosAddResumableInitValidator), | 75 | asyncMiddleware(videosAddResumableInitValidator), |
@@ -82,7 +82,7 @@ uploadRouter.delete('/upload-resumable', | |||
82 | ) | 82 | ) |
83 | 83 | ||
84 | uploadRouter.put('/upload-resumable', | 84 | uploadRouter.put('/upload-resumable', |
85 | docMiddleware('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumable'), | 85 | openapiOperationDoc({ operationId: 'uploadResumable' }), |
86 | authenticate, | 86 | authenticate, |
87 | uploadxMiddleware, // uploadx doesn't use call next() before the file upload completes | 87 | uploadxMiddleware, // uploadx doesn't use call next() before the file upload completes |
88 | asyncMiddleware(videosAddResumableValidator), | 88 | asyncMiddleware(videosAddResumableValidator), |
diff --git a/server/middlewares/doc.ts b/server/middlewares/doc.ts index aa852cd77..3db85c68d 100644 --- a/server/middlewares/doc.ts +++ b/server/middlewares/doc.ts | |||
@@ -1,13 +1,16 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | 2 | ||
3 | function docMiddleware (docUrl: string) { | 3 | function openapiOperationDoc (options: { |
4 | url?: string | ||
5 | operationId?: string | ||
6 | }) { | ||
4 | return (req: express.Request, res: express.Response, next: express.NextFunction) => { | 7 | return (req: express.Request, res: express.Response, next: express.NextFunction) => { |
5 | res.locals.docUrl = docUrl | 8 | res.locals.docUrl = options.url || 'https://docs.joinpeertube.org/api-rest-reference.html#operation/' + options.operationId |
6 | 9 | ||
7 | if (next) return next() | 10 | if (next) return next() |
8 | } | 11 | } |
9 | } | 12 | } |
10 | 13 | ||
11 | export { | 14 | export { |
12 | docMiddleware | 15 | openapiOperationDoc |
13 | } | 16 | } |