aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-11-10 09:42:37 +0100
committerChocobozzz <me@florianbigard.com>2021-11-10 09:43:33 +0100
commit020d3d3d79338148873cfd78ba59856f63260f2f (patch)
tree343218cafb3573d7285c4c4616d629f398009913 /server/controllers/api/videos
parent1868ff3db93a8f2e4ceb91aa3600b633ca00b4f7 (diff)
downloadPeerTube-020d3d3d79338148873cfd78ba59856f63260f2f.tar.gz
PeerTube-020d3d3d79338148873cfd78ba59856f63260f2f.tar.zst
PeerTube-020d3d3d79338148873cfd78ba59856f63260f2f.zip
Remove resumable cache after upload success
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/upload.ts26
1 files changed, 19 insertions, 7 deletions
diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts
index 02aadd426..3e9979330 100644
--- a/server/controllers/api/videos/upload.ts
+++ b/server/controllers/api/videos/upload.ts
@@ -19,7 +19,7 @@ import { VideoPathManager } from '@server/lib/video-path-manager'
19import { buildNextVideoState } from '@server/lib/video-state' 19import { buildNextVideoState } from '@server/lib/video-state'
20import { openapiOperationDoc } from '@server/middlewares/doc' 20import { openapiOperationDoc } from '@server/middlewares/doc'
21import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' 21import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models'
22import { uploadx } from '@uploadx/core' 22import { Uploadx } from '@uploadx/core'
23import { VideoCreate, VideoState } from '../../../../shared' 23import { VideoCreate, VideoState } from '../../../../shared'
24import { HttpStatusCode } from '../../../../shared/models' 24import { HttpStatusCode } from '../../../../shared/models'
25import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' 25import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger'
@@ -41,6 +41,7 @@ import {
41 authenticate, 41 authenticate,
42 videosAddLegacyValidator, 42 videosAddLegacyValidator,
43 videosAddResumableInitValidator, 43 videosAddResumableInitValidator,
44 videosResumableUploadIdValidator,
44 videosAddResumableValidator 45 videosAddResumableValidator
45} from '../../../middlewares' 46} from '../../../middlewares'
46import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' 47import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
@@ -50,7 +51,9 @@ import { VideoFileModel } from '../../../models/video/video-file'
50const lTags = loggerTagsFactory('api', 'video') 51const lTags = loggerTagsFactory('api', 'video')
51const auditLogger = auditLoggerFactory('videos') 52const auditLogger = auditLoggerFactory('videos')
52const uploadRouter = express.Router() 53const uploadRouter = express.Router()
53const uploadxMiddleware = uploadx.upload({ directory: getResumableUploadPath() }) 54
55const uploadx = new Uploadx({ directory: getResumableUploadPath() })
56uploadx.getUserId = (_, res: express.Response) => res.locals.oauth?.token.user.id
54 57
55const reqVideoFileAdd = createReqFiles( 58const reqVideoFileAdd = createReqFiles(
56 [ 'videofile', 'thumbnailfile', 'previewfile' ], 59 [ 'videofile', 'thumbnailfile', 'previewfile' ],
@@ -84,18 +87,21 @@ uploadRouter.post('/upload-resumable',
84 authenticate, 87 authenticate,
85 reqVideoFileAddResumable, 88 reqVideoFileAddResumable,
86 asyncMiddleware(videosAddResumableInitValidator), 89 asyncMiddleware(videosAddResumableInitValidator),
87 uploadxMiddleware 90 uploadx.upload
88) 91)
89 92
90uploadRouter.delete('/upload-resumable', 93uploadRouter.delete('/upload-resumable',
91 authenticate, 94 authenticate,
92 uploadxMiddleware 95 videosResumableUploadIdValidator,
96 asyncMiddleware(deleteUploadResumableCache),
97 uploadx.upload
93) 98)
94 99
95uploadRouter.put('/upload-resumable', 100uploadRouter.put('/upload-resumable',
96 openapiOperationDoc({ operationId: 'uploadResumable' }), 101 openapiOperationDoc({ operationId: 'uploadResumable' }),
97 authenticate, 102 authenticate,
98 uploadxMiddleware, // uploadx doesn't next() before the file upload completes 103 videosResumableUploadIdValidator,
104 uploadx.upload, // uploadx doesn't next() before the file upload completes
99 asyncMiddleware(videosAddResumableValidator), 105 asyncMiddleware(videosAddResumableValidator),
100 asyncMiddleware(addVideoResumable) 106 asyncMiddleware(addVideoResumable)
101) 107)
@@ -108,7 +114,7 @@ export {
108 114
109// --------------------------------------------------------------------------- 115// ---------------------------------------------------------------------------
110 116
111export async function addVideoLegacy (req: express.Request, res: express.Response) { 117async function addVideoLegacy (req: express.Request, res: express.Response) {
112 // Uploading the video could be long 118 // Uploading the video could be long
113 // Set timeout to 10 minutes, as Express's default is 2 minutes 119 // Set timeout to 10 minutes, as Express's default is 2 minutes
114 req.setTimeout(1000 * 60 * 10, () => { 120 req.setTimeout(1000 * 60 * 10, () => {
@@ -128,7 +134,7 @@ export async function addVideoLegacy (req: express.Request, res: express.Respons
128 return res.json(response) 134 return res.json(response)
129} 135}
130 136
131export async function addVideoResumable (req: express.Request, res: express.Response) { 137async function addVideoResumable (req: express.Request, res: express.Response) {
132 const videoPhysicalFile = res.locals.videoFileResumable 138 const videoPhysicalFile = res.locals.videoFileResumable
133 const videoInfo = videoPhysicalFile.metadata 139 const videoInfo = videoPhysicalFile.metadata
134 const files = { previewfile: videoInfo.previewfile } 140 const files = { previewfile: videoInfo.previewfile }
@@ -291,3 +297,9 @@ function createTorrentFederate (video: MVideoFullLight, videoFile: MVideoFile) {
291 }) 297 })
292 .catch(err => logger.error('Cannot federate or notify video creation %s', video.url, { err, ...lTags(video.uuid) })) 298 .catch(err => logger.error('Cannot federate or notify video creation %s', video.url, { err, ...lTags(video.uuid) }))
293} 299}
300
301async function deleteUploadResumableCache (req: express.Request, res: express.Response, next: express.NextFunction) {
302 await Redis.Instance.deleteUploadSession(req.query.upload_id)
303
304 return next()
305}