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/controllers/api/videos | |
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/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/index.ts | 13 | ||||
-rw-r--r-- | server/controllers/api/videos/upload.ts | 7 |
2 files changed, 20 insertions, 0 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index be233722c..d4e08293e 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -26,6 +26,7 @@ import { | |||
26 | setDefaultVideosSort, | 26 | setDefaultVideosSort, |
27 | videosCustomGetValidator, | 27 | videosCustomGetValidator, |
28 | videosGetValidator, | 28 | videosGetValidator, |
29 | videoSourceGetValidator, | ||
29 | videosRemoveValidator, | 30 | videosRemoveValidator, |
30 | videosSortValidator | 31 | videosSortValidator |
31 | } from '../../../middlewares' | 32 | } from '../../../middlewares' |
@@ -96,6 +97,14 @@ videosRouter.get('/:id/description', | |||
96 | asyncMiddleware(videosGetValidator), | 97 | asyncMiddleware(videosGetValidator), |
97 | asyncMiddleware(getVideoDescription) | 98 | asyncMiddleware(getVideoDescription) |
98 | ) | 99 | ) |
100 | |||
101 | videosRouter.get('/:id/source', | ||
102 | openapiOperationDoc({ operationId: 'getVideoSource' }), | ||
103 | authenticate, | ||
104 | asyncMiddleware(videoSourceGetValidator), | ||
105 | getVideoSource | ||
106 | ) | ||
107 | |||
99 | videosRouter.get('/:id', | 108 | videosRouter.get('/:id', |
100 | openapiOperationDoc({ operationId: 'getVideo' }), | 109 | openapiOperationDoc({ operationId: 'getVideo' }), |
101 | optionalAuthenticate, | 110 | optionalAuthenticate, |
@@ -155,6 +164,10 @@ async function getVideoDescription (req: express.Request, res: express.Response) | |||
155 | return res.json({ description }) | 164 | return res.json({ description }) |
156 | } | 165 | } |
157 | 166 | ||
167 | function getVideoSource (req: express.Request, res: express.Response) { | ||
168 | return res.json(res.locals.videoSource.toFormattedJSON()) | ||
169 | } | ||
170 | |||
158 | async function listVideos (req: express.Request, res: express.Response) { | 171 | async function listVideos (req: express.Request, res: express.Response) { |
159 | const serverActor = await getServerActor() | 172 | const serverActor = await getServerActor() |
160 | 173 | ||
diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts index 3afbedbb2..c5890691e 100644 --- a/server/controllers/api/videos/upload.ts +++ b/server/controllers/api/videos/upload.ts | |||
@@ -44,6 +44,7 @@ import { | |||
44 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 44 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
45 | import { VideoModel } from '../../../models/video/video' | 45 | import { VideoModel } from '../../../models/video/video' |
46 | import { VideoFileModel } from '../../../models/video/video-file' | 46 | import { VideoFileModel } from '../../../models/video/video-file' |
47 | import { VideoSourceModel } from '@server/models/video/video-source' | ||
47 | 48 | ||
48 | const lTags = loggerTagsFactory('api', 'video') | 49 | const lTags = loggerTagsFactory('api', 'video') |
49 | const auditLogger = auditLoggerFactory('videos') | 50 | const auditLogger = auditLoggerFactory('videos') |
@@ -151,6 +152,7 @@ async function addVideo (options: { | |||
151 | video.url = getLocalVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object | 152 | video.url = getLocalVideoActivityPubUrl(video) // We use the UUID, so set the URL after building the object |
152 | 153 | ||
153 | const videoFile = await buildNewFile(videoPhysicalFile) | 154 | const videoFile = await buildNewFile(videoPhysicalFile) |
155 | const originalFilename = videoPhysicalFile.originalname | ||
154 | 156 | ||
155 | // Move physical file | 157 | // Move physical file |
156 | const destination = VideoPathManager.Instance.getFSVideoFileOutputPath(video, videoFile) | 158 | const destination = VideoPathManager.Instance.getFSVideoFileOutputPath(video, videoFile) |
@@ -181,6 +183,11 @@ async function addVideo (options: { | |||
181 | 183 | ||
182 | video.VideoFiles = [ videoFile ] | 184 | video.VideoFiles = [ videoFile ] |
183 | 185 | ||
186 | await VideoSourceModel.create({ | ||
187 | filename: originalFilename, | ||
188 | videoId: video.id | ||
189 | }, { transaction: t }) | ||
190 | |||
184 | await setVideoTags({ video, tags: videoInfo.tags, transaction: t }) | 191 | await setVideoTags({ video, tags: videoInfo.tags, transaction: t }) |
185 | 192 | ||
186 | // Schedule an update in the future? | 193 | // Schedule an update in the future? |