mirror of https://github.com/Chocobozzz/PeerTube
add video upload types, add doc middleware to more routes
parent
fc21ef5c62
commit
c756bae079
|
@ -60,12 +60,25 @@ videosRouter.use('/', liveRouter)
|
||||||
videosRouter.use('/', uploadRouter)
|
videosRouter.use('/', uploadRouter)
|
||||||
videosRouter.use('/', updateRouter)
|
videosRouter.use('/', updateRouter)
|
||||||
|
|
||||||
videosRouter.get('/categories', listVideoCategories)
|
videosRouter.get('/categories',
|
||||||
videosRouter.get('/licences', listVideoLicences)
|
openapiOperationDoc({ operationId: 'getCategories' }),
|
||||||
videosRouter.get('/languages', listVideoLanguages)
|
listVideoCategories
|
||||||
videosRouter.get('/privacies', listVideoPrivacies)
|
)
|
||||||
|
videosRouter.get('/licences',
|
||||||
|
openapiOperationDoc({ operationId: 'getLicences' }),
|
||||||
|
listVideoLicences
|
||||||
|
)
|
||||||
|
videosRouter.get('/languages',
|
||||||
|
openapiOperationDoc({ operationId: 'getLanguages' }),
|
||||||
|
listVideoLanguages
|
||||||
|
)
|
||||||
|
videosRouter.get('/privacies',
|
||||||
|
openapiOperationDoc({ operationId: 'getPrivacies' }),
|
||||||
|
listVideoPrivacies
|
||||||
|
)
|
||||||
|
|
||||||
videosRouter.get('/',
|
videosRouter.get('/',
|
||||||
|
openapiOperationDoc({ operationId: 'getVideos' }),
|
||||||
paginationValidator,
|
paginationValidator,
|
||||||
videosSortValidator,
|
videosSortValidator,
|
||||||
setDefaultVideosSort,
|
setDefaultVideosSort,
|
||||||
|
@ -76,6 +89,7 @@ videosRouter.get('/',
|
||||||
)
|
)
|
||||||
|
|
||||||
videosRouter.get('/:id/description',
|
videosRouter.get('/:id/description',
|
||||||
|
openapiOperationDoc({ operationId: 'getVideoDesc' }),
|
||||||
asyncMiddleware(videosGetValidator),
|
asyncMiddleware(videosGetValidator),
|
||||||
asyncMiddleware(getVideoDescription)
|
asyncMiddleware(getVideoDescription)
|
||||||
)
|
)
|
||||||
|
@ -91,6 +105,7 @@ videosRouter.get('/:id',
|
||||||
asyncMiddleware(getVideo)
|
asyncMiddleware(getVideo)
|
||||||
)
|
)
|
||||||
videosRouter.post('/:id/views',
|
videosRouter.post('/:id/views',
|
||||||
|
openapiOperationDoc({ operationId: 'addView' }),
|
||||||
asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')),
|
asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')),
|
||||||
asyncMiddleware(viewVideo)
|
asyncMiddleware(viewVideo)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
import * as express from 'express'
|
import * as express from 'express'
|
||||||
import { UserWatchingVideo } from '../../../../shared'
|
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 { UserVideoHistoryModel } from '../../../models/user/user-video-history'
|
||||||
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
|
||||||
|
|
||||||
const watchingRouter = express.Router()
|
const watchingRouter = express.Router()
|
||||||
|
|
||||||
watchingRouter.put('/:videoId/watching',
|
watchingRouter.put('/:videoId/watching',
|
||||||
|
openapiOperationDoc({ operationId: 'setProgress' }),
|
||||||
authenticate,
|
authenticate,
|
||||||
asyncMiddleware(videoWatchingValidator),
|
asyncMiddleware(videoWatchingValidator),
|
||||||
asyncRetryTransactionMiddleware(userWatchVideo)
|
asyncRetryTransactionMiddleware(userWatchVideo)
|
||||||
|
|
|
@ -72,7 +72,8 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
|
||||||
|
|
||||||
return res.fail({
|
return res.fail({
|
||||||
status: HttpStatusCode.FORBIDDEN_403,
|
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({
|
return res.fail({
|
||||||
status: HttpStatusCode.FORBIDDEN_403,
|
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({
|
return res.fail({
|
||||||
status: HttpStatusCode.FORBIDDEN_403,
|
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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,7 +402,8 @@ const videosAcceptChangeOwnershipValidator = [
|
||||||
if (isAble === false) {
|
if (isAble === false) {
|
||||||
res.fail({
|
res.fail({
|
||||||
status: HttpStatusCode.PAYLOAD_TOO_LARGE_413,
|
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
|
return
|
||||||
}
|
}
|
||||||
|
@ -628,7 +629,8 @@ async function commonVideoChecksPass (parameters: {
|
||||||
if (!isVideoFileSizeValid(videoFileSize.toString())) {
|
if (!isVideoFileSizeValid(videoFileSize.toString())) {
|
||||||
res.fail({
|
res.fail({
|
||||||
status: HttpStatusCode.PAYLOAD_TOO_LARGE_413,
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
@ -636,7 +638,8 @@ async function commonVideoChecksPass (parameters: {
|
||||||
if (await isAbleToUploadVideo(user.id, videoFileSize) === false) {
|
if (await isAbleToUploadVideo(user.id, videoFileSize) === false) {
|
||||||
res.fail({
|
res.fail({
|
||||||
status: HttpStatusCode.PAYLOAD_TOO_LARGE_413,
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,15 @@
|
||||||
export const enum ServerErrorCode {
|
export const enum ServerErrorCode {
|
||||||
|
/**
|
||||||
|
* The simplest form of payload too large: when the file size is over the
|
||||||
|
* global file size limit
|
||||||
|
*/
|
||||||
|
MAX_FILE_SIZE_REACHED = 'max_file_size_reached',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The payload is too large for the user quota set
|
||||||
|
*/
|
||||||
|
QUOTA_REACHED = 'quota_reached',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error yielded upon trying to access a video that is not federated, nor can
|
* Error yielded upon trying to access a video that is not federated, nor can
|
||||||
* be. This may be due to: remote videos on instances that are not followed by
|
* be. This may be due to: remote videos on instances that are not followed by
|
||||||
|
@ -6,13 +17,15 @@ export const enum ServerErrorCode {
|
||||||
*/
|
*/
|
||||||
DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS = 'does_not_respect_follow_constraints',
|
DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS = 'does_not_respect_follow_constraints',
|
||||||
|
|
||||||
|
LIVE_NOT_ENABLED = 'live_not_enabled',
|
||||||
|
LIVE_NOT_ALLOWING_REPLAY = 'live_not_allowing_replay',
|
||||||
|
LIVE_CONFLICTING_PERMANENT_AND_SAVE_REPLAY = 'live_conflicting_permanent_and_save_replay',
|
||||||
/**
|
/**
|
||||||
* Pretty self-explanatory: the set maximum number of simultaneous lives was
|
* Pretty self-explanatory: the set maximum number of simultaneous lives was
|
||||||
* reached, and this error is typically there to inform the user trying to
|
* reached, and this error is typically there to inform the user trying to
|
||||||
* broadcast one.
|
* broadcast one.
|
||||||
*/
|
*/
|
||||||
MAX_INSTANCE_LIVES_LIMIT_REACHED = 'max_instance_lives_limit_reached',
|
MAX_INSTANCE_LIVES_LIMIT_REACHED = 'max_instance_lives_limit_reached',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pretty self-explanatory: the set maximum number of simultaneous lives FOR
|
* Pretty self-explanatory: the set maximum number of simultaneous lives FOR
|
||||||
* THIS USER was reached, and this error is typically there to inform the user
|
* THIS USER was reached, and this error is typically there to inform the user
|
||||||
|
|
|
@ -1802,6 +1802,7 @@ paths:
|
||||||
'/videos/{id}/views':
|
'/videos/{id}/views':
|
||||||
post:
|
post:
|
||||||
summary: Add a view to a video
|
summary: Add a view to a video
|
||||||
|
operationId: addView
|
||||||
tags:
|
tags:
|
||||||
- Video
|
- Video
|
||||||
parameters:
|
parameters:
|
||||||
|
@ -1813,6 +1814,7 @@ paths:
|
||||||
'/videos/{id}/watching':
|
'/videos/{id}/watching':
|
||||||
put:
|
put:
|
||||||
summary: Set watching progress of a video
|
summary: Set watching progress of a video
|
||||||
|
operationId: setProgress
|
||||||
tags:
|
tags:
|
||||||
- Video
|
- Video
|
||||||
security:
|
security:
|
||||||
|
@ -1851,7 +1853,10 @@ paths:
|
||||||
'408':
|
'408':
|
||||||
description: upload has timed out
|
description: upload has timed out
|
||||||
'413':
|
'413':
|
||||||
description: video file too large, due to quota or max body size limit set by the reverse-proxy
|
x-summary: video file too large, due to quota or max body size limit set by the reverse-proxy
|
||||||
|
description: |
|
||||||
|
If the response has no body, it means the reverse-proxy didn't let it through. Otherwise disambiguate via `type`:
|
||||||
|
- `quota_reached` for quota limits wether daily or global
|
||||||
headers:
|
headers:
|
||||||
X-File-Maximum-Size:
|
X-File-Maximum-Size:
|
||||||
schema:
|
schema:
|
||||||
|
@ -1951,7 +1956,11 @@ paths:
|
||||||
type: number
|
type: number
|
||||||
example: 0
|
example: 0
|
||||||
'413':
|
'413':
|
||||||
description: video file too large, due to quota, absolute max file size or concurrent partial upload limit
|
x-summary: video file too large, due to quota, absolute max file size or concurrent partial upload limit
|
||||||
|
description: |
|
||||||
|
Disambiguate via `type`:
|
||||||
|
- `max_file_size_reached` for the absolute file size limit
|
||||||
|
- `quota_reached` for quota limits whether daily or global
|
||||||
'415':
|
'415':
|
||||||
description: video type unsupported
|
description: video type unsupported
|
||||||
put:
|
put:
|
||||||
|
@ -2027,10 +2036,14 @@ paths:
|
||||||
example: 0
|
example: 0
|
||||||
'403':
|
'403':
|
||||||
description: video didn't pass upload filter
|
description: video didn't pass upload filter
|
||||||
'413':
|
'404':
|
||||||
description: video file too large, due to quota or max body size limit set by the reverse-proxy
|
description: upload not found
|
||||||
|
'409':
|
||||||
|
description: chunk doesn't match range
|
||||||
'422':
|
'422':
|
||||||
description: video unreadable
|
description: video unreadable
|
||||||
|
'429':
|
||||||
|
description: too many concurrent requests
|
||||||
delete:
|
delete:
|
||||||
summary: Cancel the resumable upload of a video, deleting any data uploaded so far
|
summary: Cancel the resumable upload of a video, deleting any data uploaded so far
|
||||||
description: Uses [a resumable protocol](https://github.com/kukhariev/node-uploadx/blob/master/proto.md) to cancel the upload of a video
|
description: Uses [a resumable protocol](https://github.com/kukhariev/node-uploadx/blob/master/proto.md) to cancel the upload of a video
|
||||||
|
@ -2063,6 +2076,8 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
type: number
|
type: number
|
||||||
example: 0
|
example: 0
|
||||||
|
'404':
|
||||||
|
description: upload not found
|
||||||
|
|
||||||
/videos/imports:
|
/videos/imports:
|
||||||
post:
|
post:
|
||||||
|
@ -2116,8 +2131,20 @@ paths:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/VideoUploadResponse'
|
$ref: '#/components/schemas/VideoUploadResponse'
|
||||||
|
'400':
|
||||||
|
x-summary: validation error, or conflicting `saveReplay` and `permanentLive` parameter set
|
||||||
|
description: |
|
||||||
|
Disambiguate via `type`:
|
||||||
|
- default type for a validation error
|
||||||
|
- `live_conflicting_permanent_and_save_replay` for conflicting parameters set
|
||||||
'403':
|
'403':
|
||||||
description: live is not enabled, allow replay is not enabled, or max instance/user live videos limit is exceeded
|
x-summary: live is not enabled, allow replay is not enabled, or max instance/user live videos limit is exceeded
|
||||||
|
description: |
|
||||||
|
Disambiguate via `type`:
|
||||||
|
- `live_not_enabled` for a disabled live feature
|
||||||
|
- `live_not_allowing_replay` for a disabled replay feature
|
||||||
|
- `max_instance_lives_limit_reached` for the absolute concurrent live limit
|
||||||
|
- `max_user_lives_limit_reached` for the user concurrent live limit
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
multipart/form-data:
|
multipart/form-data:
|
||||||
|
@ -2318,7 +2345,7 @@ paths:
|
||||||
type: string
|
type: string
|
||||||
- name: videoIs
|
- name: videoIs
|
||||||
in: query
|
in: query
|
||||||
description: only list blacklisted or deleted videos
|
description: only list deleted or blocklisted videos
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
enum:
|
enum:
|
||||||
|
@ -4396,7 +4423,7 @@ components:
|
||||||
name: sort
|
name: sort
|
||||||
in: query
|
in: query
|
||||||
required: false
|
required: false
|
||||||
description: Sort blacklists by criteria
|
description: Sort blocklists by criteria
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
enum:
|
enum:
|
||||||
|
@ -4859,7 +4886,7 @@ components:
|
||||||
enum:
|
enum:
|
||||||
- 0
|
- 0
|
||||||
- 1
|
- 1
|
||||||
description: 'Admin flags for the user (None = `0`, Bypass video blacklist = `1`)'
|
description: 'Admin flags for the user (None = `0`, Bypass video blocklist = `1`)'
|
||||||
example: 1
|
example: 1
|
||||||
|
|
||||||
VideoStateConstant:
|
VideoStateConstant:
|
||||||
|
|
Loading…
Reference in New Issue