diff options
author | kontrollanten <6680299+kontrollanten@users.noreply.github.com> | 2022-06-21 15:31:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-21 15:31:25 +0200 |
commit | 2e401e8575decb1d491d0db48ca1ab1eba5b2a66 (patch) | |
tree | eee1e6213ca4d635837ca01c2bdc5c876b8d8b7d /server/middlewares/validators | |
parent | dec49521556fc228c6e05b6199e9b07f619b38fb (diff) | |
download | PeerTube-2e401e8575decb1d491d0db48ca1ab1eba5b2a66.tar.gz PeerTube-2e401e8575decb1d491d0db48ca1ab1eba5b2a66.tar.zst PeerTube-2e401e8575decb1d491d0db48ca1ab1eba5b2a66.zip |
store uploaded video filename (#4885)
* store uploaded video filename
closes #4731
* dont crash if videos channel exist
* migration: use raw query
* video source: fixes after code review
* cleanup
* bump migration
* updates after code review
* refactor: use checkUserCanManageVideo
* videoSource: add openapi doc
* test(check-params/video-source): fix timeout
* Styling
* Correctly set original filename as source
Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/videos/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/videos/video-source.ts | 37 | ||||
-rw-r--r-- | server/middlewares/validators/videos/videos.ts | 2 |
3 files changed, 39 insertions, 1 deletions
diff --git a/server/middlewares/validators/videos/index.ts b/server/middlewares/validators/videos/index.ts index bd2590bc5..1dd7b5d2e 100644 --- a/server/middlewares/validators/videos/index.ts +++ b/server/middlewares/validators/videos/index.ts | |||
@@ -9,6 +9,7 @@ export * from './video-ownership-changes' | |||
9 | export * from './video-view' | 9 | export * from './video-view' |
10 | export * from './video-rates' | 10 | export * from './video-rates' |
11 | export * from './video-shares' | 11 | export * from './video-shares' |
12 | export * from './video-source' | ||
12 | export * from './video-stats' | 13 | export * from './video-stats' |
13 | export * from './video-studio' | 14 | export * from './video-studio' |
14 | export * from './video-transcoding' | 15 | export * from './video-transcoding' |
diff --git a/server/middlewares/validators/videos/video-source.ts b/server/middlewares/validators/videos/video-source.ts new file mode 100644 index 000000000..31a2f16b3 --- /dev/null +++ b/server/middlewares/validators/videos/video-source.ts | |||
@@ -0,0 +1,37 @@ | |||
1 | import express from 'express' | ||
2 | import { getVideoWithAttributes } from '@server/helpers/video' | ||
3 | import { VideoSourceModel } from '@server/models/video/video-source' | ||
4 | import { MVideoFullLight } from '@server/types/models' | ||
5 | import { HttpStatusCode, UserRight } from '@shared/models' | ||
6 | import { logger } from '../../../helpers/logger' | ||
7 | import { areValidationErrors, checkUserCanManageVideo, doesVideoExist, isValidVideoIdParam } from '../shared' | ||
8 | |||
9 | const videoSourceGetValidator = [ | ||
10 | isValidVideoIdParam('id'), | ||
11 | |||
12 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
13 | logger.debug('Checking videoSourceGet parameters', { parameters: req.params }) | ||
14 | |||
15 | if (areValidationErrors(req, res)) return | ||
16 | if (!await doesVideoExist(req.params.id, res, 'for-api')) return | ||
17 | |||
18 | const video = getVideoWithAttributes(res) as MVideoFullLight | ||
19 | |||
20 | res.locals.videoSource = await VideoSourceModel.loadByVideoId(video.id) | ||
21 | if (!res.locals.videoSource) { | ||
22 | return res.fail({ | ||
23 | status: HttpStatusCode.NOT_FOUND_404, | ||
24 | message: 'Video source not found' | ||
25 | }) | ||
26 | } | ||
27 | |||
28 | const user = res.locals.oauth.token.User | ||
29 | if (!checkUserCanManageVideo(user, video, UserRight.UPDATE_ANY_VIDEO, res)) return | ||
30 | |||
31 | return next() | ||
32 | } | ||
33 | ] | ||
34 | |||
35 | export { | ||
36 | videoSourceGetValidator | ||
37 | } | ||
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 0b6b8bfe5..c75c3640b 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts | |||
@@ -152,7 +152,7 @@ const videosAddResumableValidator = [ | |||
152 | 152 | ||
153 | if (!await isVideoAccepted(req, res, file)) return cleanup() | 153 | if (!await isVideoAccepted(req, res, file)) return cleanup() |
154 | 154 | ||
155 | res.locals.videoFileResumable = file | 155 | res.locals.videoFileResumable = { ...file, originalname: file.filename } |
156 | 156 | ||
157 | return next() | 157 | return next() |
158 | } | 158 | } |