aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r--server/controllers/api/videos/index.ts53
1 files changed, 26 insertions, 27 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index f639df098..3ec9d97bb 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -61,8 +61,7 @@ const storage = multer.diskStorage({
61 else if (file.mimetype === 'video/ogg') extension = 'ogv' 61 else if (file.mimetype === 'video/ogg') extension = 'ogv'
62 generateRandomString(16) 62 generateRandomString(16)
63 .then(randomString => { 63 .then(randomString => {
64 const filename = randomString 64 cb(null, randomString + '.' + extension)
65 cb(null, filename + '.' + extension)
66 }) 65 })
67 .catch(err => { 66 .catch(err => {
68 logger.error('Cannot generate random string for file name.', err) 67 logger.error('Cannot generate random string for file name.', err)
@@ -128,15 +127,15 @@ export {
128 127
129// --------------------------------------------------------------------------- 128// ---------------------------------------------------------------------------
130 129
131function listVideoCategories (req: express.Request, res: express.Response, next: express.NextFunction) { 130function listVideoCategories (req: express.Request, res: express.Response) {
132 res.json(VIDEO_CATEGORIES) 131 res.json(VIDEO_CATEGORIES)
133} 132}
134 133
135function listVideoLicences (req: express.Request, res: express.Response, next: express.NextFunction) { 134function listVideoLicences (req: express.Request, res: express.Response) {
136 res.json(VIDEO_LICENCES) 135 res.json(VIDEO_LICENCES)
137} 136}
138 137
139function listVideoLanguages (req: express.Request, res: express.Response, next: express.NextFunction) { 138function listVideoLanguages (req: express.Request, res: express.Response) {
140 res.json(VIDEO_LANGUAGES) 139 res.json(VIDEO_LANGUAGES)
141} 140}
142 141
@@ -144,7 +143,7 @@ function listVideoLanguages (req: express.Request, res: express.Response, next:
144// We need this because we run the transaction in SERIALIZABLE isolation that can fail 143// We need this because we run the transaction in SERIALIZABLE isolation that can fail
145function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { 144function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
146 const options = { 145 const options = {
147 arguments: [ req, res, req.files.videofile[0] ], 146 arguments: [ req, res, req.files['videofile'][0] ],
148 errorMessage: 'Cannot insert the video with many retries.' 147 errorMessage: 'Cannot insert the video with many retries.'
149 } 148 }
150 149
@@ -157,7 +156,7 @@ function addVideoRetryWrapper (req: express.Request, res: express.Response, next
157} 156}
158 157
159function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) { 158function addVideo (req: express.Request, res: express.Response, videoPhysicalFile: Express.Multer.File) {
160 const videoInfos: VideoCreate = req.body 159 const videoInfo: VideoCreate = req.body
161 160
162 return db.sequelize.transaction(t => { 161 return db.sequelize.transaction(t => {
163 const user = res.locals.oauth.token.User 162 const user = res.locals.oauth.token.User
@@ -169,21 +168,21 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
169 168
170 return db.Author.findOrCreateAuthor(name, podId, userId, t) 169 return db.Author.findOrCreateAuthor(name, podId, userId, t)
171 .then(author => { 170 .then(author => {
172 const tags = videoInfos.tags 171 const tags = videoInfo.tags
173 if (!tags) return { author, tagInstances: undefined } 172 if (!tags) return { author, tagInstances: undefined }
174 173
175 return db.Tag.findOrCreateTags(tags, t).then(tagInstances => ({ author, tagInstances })) 174 return db.Tag.findOrCreateTags(tags, t).then(tagInstances => ({ author, tagInstances }))
176 }) 175 })
177 .then(({ author, tagInstances }) => { 176 .then(({ author, tagInstances }) => {
178 const videoData = { 177 const videoData = {
179 name: videoInfos.name, 178 name: videoInfo.name,
180 remote: false, 179 remote: false,
181 extname: extname(videoPhysicalFile.filename), 180 extname: extname(videoPhysicalFile.filename),
182 category: videoInfos.category, 181 category: videoInfo.category,
183 licence: videoInfos.licence, 182 licence: videoInfo.licence,
184 language: videoInfos.language, 183 language: videoInfo.language,
185 nsfw: videoInfos.nsfw, 184 nsfw: videoInfo.nsfw,
186 description: videoInfos.description, 185 description: videoInfo.description,
187 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware 186 duration: videoPhysicalFile['duration'], // duration was added by a previous middleware
188 authorId: author.id 187 authorId: author.id
189 } 188 }
@@ -240,7 +239,7 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
240 239
241 return video.save(options) 240 return video.save(options)
242 .then(videoCreated => { 241 .then(videoCreated => {
243 // Do not forget to add Author informations to the created video 242 // Do not forget to add Author information to the created video
244 videoCreated.Author = author 243 videoCreated.Author = author
245 244
246 return { tagInstances, video: videoCreated, videoFile } 245 return { tagInstances, video: videoCreated, videoFile }
@@ -265,7 +264,7 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
265 }) 264 })
266 }) 265 })
267 .then(video => { 266 .then(video => {
268 // Let transcoding job send the video to friends because the videofile extension might change 267 // Let transcoding job send the video to friends because the video file extension might change
269 if (CONFIG.TRANSCODING.ENABLED === true) return undefined 268 if (CONFIG.TRANSCODING.ENABLED === true) return undefined
270 269
271 return video.toAddRemoteJSON() 270 return video.toAddRemoteJSON()
@@ -275,7 +274,7 @@ function addVideo (req: express.Request, res: express.Response, videoPhysicalFil
275 }) 274 })
276 }) 275 })
277 }) 276 })
278 .then(() => logger.info('Video with name %s created.', videoInfos.name)) 277 .then(() => logger.info('Video with name %s created.', videoInfo.name))
279 .catch((err: Error) => { 278 .catch((err: Error) => {
280 logger.debug('Cannot insert the video.', err) 279 logger.debug('Cannot insert the video.', err)
281 throw err 280 throw err
@@ -299,14 +298,14 @@ function updateVideoRetryWrapper (req: express.Request, res: express.Response, n
299function updateVideo (req: express.Request, res: express.Response) { 298function updateVideo (req: express.Request, res: express.Response) {
300 const videoInstance = res.locals.video 299 const videoInstance = res.locals.video
301 const videoFieldsSave = videoInstance.toJSON() 300 const videoFieldsSave = videoInstance.toJSON()
302 const videoInfosToUpdate: VideoUpdate = req.body 301 const videoInfoToUpdate: VideoUpdate = req.body
303 302
304 return db.sequelize.transaction(t => { 303 return db.sequelize.transaction(t => {
305 let tagsPromise: Promise<TagInstance[]> 304 let tagsPromise: Promise<TagInstance[]>
306 if (!videoInfosToUpdate.tags) { 305 if (!videoInfoToUpdate.tags) {
307 tagsPromise = Promise.resolve(null) 306 tagsPromise = Promise.resolve(null)
308 } else { 307 } else {
309 tagsPromise = db.Tag.findOrCreateTags(videoInfosToUpdate.tags, t) 308 tagsPromise = db.Tag.findOrCreateTags(videoInfoToUpdate.tags, t)
310 } 309 }
311 310
312 return tagsPromise 311 return tagsPromise
@@ -315,12 +314,12 @@ function updateVideo (req: express.Request, res: express.Response) {
315 transaction: t 314 transaction: t
316 } 315 }
317 316
318 if (videoInfosToUpdate.name !== undefined) videoInstance.set('name', videoInfosToUpdate.name) 317 if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name)
319 if (videoInfosToUpdate.category !== undefined) videoInstance.set('category', videoInfosToUpdate.category) 318 if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category)
320 if (videoInfosToUpdate.licence !== undefined) videoInstance.set('licence', videoInfosToUpdate.licence) 319 if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
321 if (videoInfosToUpdate.language !== undefined) videoInstance.set('language', videoInfosToUpdate.language) 320 if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
322 if (videoInfosToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfosToUpdate.nsfw) 321 if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
323 if (videoInfosToUpdate.description !== undefined) videoInstance.set('description', videoInfosToUpdate.description) 322 if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
324 323
325 return videoInstance.save(options).then(() => tagInstances) 324 return videoInstance.save(options).then(() => tagInstances)
326 }) 325 })
@@ -360,7 +359,7 @@ function updateVideo (req: express.Request, res: express.Response) {
360 }) 359 })
361} 360}
362 361
363function getVideo (req: express.Request, res: express.Response, next: express.NextFunction) { 362function getVideo (req: express.Request, res: express.Response) {
364 const videoInstance = res.locals.video 363 const videoInstance = res.locals.video
365 364
366 if (videoInstance.isOwned()) { 365 if (videoInstance.isOwned()) {