diff options
Diffstat (limited to 'server/controllers/api/videos/index.ts')
-rw-r--r-- | server/controllers/api/videos/index.ts | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index b82b0936f..bfa018031 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -1,4 +1,5 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as Sequelize from 'sequelize' | ||
2 | import * as fs from 'fs' | 3 | import * as fs from 'fs' |
3 | import * as multer from 'multer' | 4 | import * as multer from 'multer' |
4 | import * as path from 'path' | 5 | import * as path from 'path' |
@@ -124,21 +125,21 @@ export { | |||
124 | 125 | ||
125 | // --------------------------------------------------------------------------- | 126 | // --------------------------------------------------------------------------- |
126 | 127 | ||
127 | function listVideoCategories (req, res, next) { | 128 | function listVideoCategories (req: express.Request, res: express.Response, next: express.NextFunction) { |
128 | res.json(VIDEO_CATEGORIES) | 129 | res.json(VIDEO_CATEGORIES) |
129 | } | 130 | } |
130 | 131 | ||
131 | function listVideoLicences (req, res, next) { | 132 | function listVideoLicences (req: express.Request, res: express.Response, next: express.NextFunction) { |
132 | res.json(VIDEO_LICENCES) | 133 | res.json(VIDEO_LICENCES) |
133 | } | 134 | } |
134 | 135 | ||
135 | function listVideoLanguages (req, res, next) { | 136 | function listVideoLanguages (req: express.Request, res: express.Response, next: express.NextFunction) { |
136 | res.json(VIDEO_LANGUAGES) | 137 | res.json(VIDEO_LANGUAGES) |
137 | } | 138 | } |
138 | 139 | ||
139 | // Wrapper to video add that retry the function if there is a database error | 140 | // Wrapper to video add that retry the function if there is a database error |
140 | // We need this because we run the transaction in SERIALIZABLE isolation that can fail | 141 | // We need this because we run the transaction in SERIALIZABLE isolation that can fail |
141 | function addVideoRetryWrapper (req, res, next) { | 142 | function addVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
142 | const options = { | 143 | const options = { |
143 | arguments: [ req, res, req.files.videofile[0] ], | 144 | arguments: [ req, res, req.files.videofile[0] ], |
144 | errorMessage: 'Cannot insert the video with many retries.' | 145 | errorMessage: 'Cannot insert the video with many retries.' |
@@ -152,7 +153,7 @@ function addVideoRetryWrapper (req, res, next) { | |||
152 | }) | 153 | }) |
153 | } | 154 | } |
154 | 155 | ||
155 | function addVideo (req, res, videoFile, finalCallback) { | 156 | function addVideo (req: express.Request, res: express.Response, videoFile: Express.Multer.File, finalCallback: (err: Error) => void) { |
156 | const videoInfos = req.body | 157 | const videoInfos = req.body |
157 | 158 | ||
158 | waterfall([ | 159 | waterfall([ |
@@ -190,7 +191,7 @@ function addVideo (req, res, videoFile, finalCallback) { | |||
190 | language: videoInfos.language, | 191 | language: videoInfos.language, |
191 | nsfw: videoInfos.nsfw, | 192 | nsfw: videoInfos.nsfw, |
192 | description: videoInfos.description, | 193 | description: videoInfos.description, |
193 | duration: videoFile.duration, | 194 | duration: videoFile['duration'], // duration was added by a previous middleware |
194 | authorId: author.id | 195 | authorId: author.id |
195 | } | 196 | } |
196 | 197 | ||
@@ -254,7 +255,7 @@ function addVideo (req, res, videoFile, finalCallback) { | |||
254 | 255 | ||
255 | commitTransaction | 256 | commitTransaction |
256 | 257 | ||
257 | ], function andFinally (err, t) { | 258 | ], function andFinally (err: Error, t: Sequelize.Transaction) { |
258 | if (err) { | 259 | if (err) { |
259 | // This is just a debug because we will retry the insert | 260 | // This is just a debug because we will retry the insert |
260 | logger.debug('Cannot insert the video.', { error: err }) | 261 | logger.debug('Cannot insert the video.', { error: err }) |
@@ -266,7 +267,7 @@ function addVideo (req, res, videoFile, finalCallback) { | |||
266 | }) | 267 | }) |
267 | } | 268 | } |
268 | 269 | ||
269 | function updateVideoRetryWrapper (req, res, next) { | 270 | function updateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
270 | const options = { | 271 | const options = { |
271 | arguments: [ req, res ], | 272 | arguments: [ req, res ], |
272 | errorMessage: 'Cannot update the video with many retries.' | 273 | errorMessage: 'Cannot update the video with many retries.' |
@@ -280,7 +281,7 @@ function updateVideoRetryWrapper (req, res, next) { | |||
280 | }) | 281 | }) |
281 | } | 282 | } |
282 | 283 | ||
283 | function updateVideo (req, res, finalCallback) { | 284 | function updateVideo (req: express.Request, res: express.Response, finalCallback: (err: Error) => void) { |
284 | const videoInstance = res.locals.video | 285 | const videoInstance = res.locals.video |
285 | const videoFieldsSave = videoInstance.toJSON() | 286 | const videoFieldsSave = videoInstance.toJSON() |
286 | const videoInfosToUpdate = req.body | 287 | const videoInfosToUpdate = req.body |
@@ -341,7 +342,7 @@ function updateVideo (req, res, finalCallback) { | |||
341 | 342 | ||
342 | commitTransaction | 343 | commitTransaction |
343 | 344 | ||
344 | ], function andFinally (err, t) { | 345 | ], function andFinally (err: Error, t: Sequelize.Transaction) { |
345 | if (err) { | 346 | if (err) { |
346 | logger.debug('Cannot update the video.', { error: err }) | 347 | logger.debug('Cannot update the video.', { error: err }) |
347 | 348 | ||
@@ -361,7 +362,7 @@ function updateVideo (req, res, finalCallback) { | |||
361 | }) | 362 | }) |
362 | } | 363 | } |
363 | 364 | ||
364 | function getVideo (req, res, next) { | 365 | function getVideo (req: express.Request, res: express.Response, next: express.NextFunction) { |
365 | const videoInstance = res.locals.video | 366 | const videoInstance = res.locals.video |
366 | 367 | ||
367 | if (videoInstance.isOwned()) { | 368 | if (videoInstance.isOwned()) { |
@@ -393,7 +394,7 @@ function getVideo (req, res, next) { | |||
393 | res.json(videoInstance.toFormatedJSON()) | 394 | res.json(videoInstance.toFormatedJSON()) |
394 | } | 395 | } |
395 | 396 | ||
396 | function listVideos (req, res, next) { | 397 | function listVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
397 | db.Video.listForApi(req.query.start, req.query.count, req.query.sort, function (err, videosList, videosTotal) { | 398 | db.Video.listForApi(req.query.start, req.query.count, req.query.sort, function (err, videosList, videosTotal) { |
398 | if (err) return next(err) | 399 | if (err) return next(err) |
399 | 400 | ||
@@ -401,7 +402,7 @@ function listVideos (req, res, next) { | |||
401 | }) | 402 | }) |
402 | } | 403 | } |
403 | 404 | ||
404 | function removeVideo (req, res, next) { | 405 | function removeVideo (req: express.Request, res: express.Response, next: express.NextFunction) { |
405 | const videoInstance = res.locals.video | 406 | const videoInstance = res.locals.video |
406 | 407 | ||
407 | videoInstance.destroy().asCallback(function (err) { | 408 | videoInstance.destroy().asCallback(function (err) { |
@@ -414,7 +415,7 @@ function removeVideo (req, res, next) { | |||
414 | }) | 415 | }) |
415 | } | 416 | } |
416 | 417 | ||
417 | function searchVideos (req, res, next) { | 418 | function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
418 | db.Video.searchAndPopulateAuthorAndPodAndTags( | 419 | db.Video.searchAndPopulateAuthorAndPodAndTags( |
419 | req.params.value, req.query.field, req.query.start, req.query.count, req.query.sort, | 420 | req.params.value, req.query.field, req.query.start, req.query.count, req.query.sort, |
420 | function (err, videosList, videosTotal) { | 421 | function (err, videosList, videosTotal) { |