diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-06-10 22:15:25 +0200 |
commit | 69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch) | |
tree | ad199a18ec3c322460d6f9523fc383ee562554e0 /server/controllers/api/videos | |
parent | 4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff) | |
download | PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip |
Type functions
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 9 | ||||
-rw-r--r-- | server/controllers/api/videos/blacklist.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 29 | ||||
-rw-r--r-- | server/controllers/api/videos/rate.ts | 7 |
4 files changed, 25 insertions, 22 deletions
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 68db025b7..78e8e8b3d 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.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 { waterfall } from 'async' | 3 | import { waterfall } from 'async' |
3 | 4 | ||
4 | import { database as db } from '../../../initializers/database' | 5 | import { database as db } from '../../../initializers/database' |
@@ -46,7 +47,7 @@ export { | |||
46 | 47 | ||
47 | // --------------------------------------------------------------------------- | 48 | // --------------------------------------------------------------------------- |
48 | 49 | ||
49 | function listVideoAbuses (req, res, next) { | 50 | function listVideoAbuses (req: express.Request, res: express.Response, next: express.NextFunction) { |
50 | db.VideoAbuse.listForApi(req.query.start, req.query.count, req.query.sort, function (err, abusesList, abusesTotal) { | 51 | db.VideoAbuse.listForApi(req.query.start, req.query.count, req.query.sort, function (err, abusesList, abusesTotal) { |
51 | if (err) return next(err) | 52 | if (err) return next(err) |
52 | 53 | ||
@@ -54,7 +55,7 @@ function listVideoAbuses (req, res, next) { | |||
54 | }) | 55 | }) |
55 | } | 56 | } |
56 | 57 | ||
57 | function reportVideoAbuseRetryWrapper (req, res, next) { | 58 | function reportVideoAbuseRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
58 | const options = { | 59 | const options = { |
59 | arguments: [ req, res ], | 60 | arguments: [ req, res ], |
60 | errorMessage: 'Cannot report abuse to the video with many retries.' | 61 | errorMessage: 'Cannot report abuse to the video with many retries.' |
@@ -67,7 +68,7 @@ function reportVideoAbuseRetryWrapper (req, res, next) { | |||
67 | }) | 68 | }) |
68 | } | 69 | } |
69 | 70 | ||
70 | function reportVideoAbuse (req, res, finalCallback) { | 71 | function reportVideoAbuse (req: express.Request, res: express.Response, finalCallback: (err: Error) => void) { |
71 | const videoInstance = res.locals.video | 72 | const videoInstance = res.locals.video |
72 | const reporterUsername = res.locals.oauth.token.User.username | 73 | const reporterUsername = res.locals.oauth.token.User.username |
73 | 74 | ||
@@ -105,7 +106,7 @@ function reportVideoAbuse (req, res, finalCallback) { | |||
105 | 106 | ||
106 | commitTransaction | 107 | commitTransaction |
107 | 108 | ||
108 | ], function andFinally (err, t) { | 109 | ], function andFinally (err: Error, t: Sequelize.Transaction) { |
109 | if (err) { | 110 | if (err) { |
110 | logger.debug('Cannot update the video.', { error: err }) | 111 | logger.debug('Cannot update the video.', { error: err }) |
111 | return rollbackTransaction(err, t, finalCallback) | 112 | return rollbackTransaction(err, t, finalCallback) |
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts index 58960798b..4b42fc2d7 100644 --- a/server/controllers/api/videos/blacklist.ts +++ b/server/controllers/api/videos/blacklist.ts | |||
@@ -25,7 +25,7 @@ export { | |||
25 | 25 | ||
26 | // --------------------------------------------------------------------------- | 26 | // --------------------------------------------------------------------------- |
27 | 27 | ||
28 | function addVideoToBlacklist (req, res, next) { | 28 | function addVideoToBlacklist (req: express.Request, res: express.Response, next: express.NextFunction) { |
29 | const videoInstance = res.locals.video | 29 | const videoInstance = res.locals.video |
30 | 30 | ||
31 | const toCreate = { | 31 | const toCreate = { |
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) { |
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 1bc575675..afdd099f8 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.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 { waterfall } from 'async' | 3 | import { waterfall } from 'async' |
3 | 4 | ||
4 | import { database as db } from '../../../initializers/database' | 5 | import { database as db } from '../../../initializers/database' |
@@ -39,7 +40,7 @@ export { | |||
39 | 40 | ||
40 | // --------------------------------------------------------------------------- | 41 | // --------------------------------------------------------------------------- |
41 | 42 | ||
42 | function rateVideoRetryWrapper (req, res, next) { | 43 | function rateVideoRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { |
43 | const options = { | 44 | const options = { |
44 | arguments: [ req, res ], | 45 | arguments: [ req, res ], |
45 | errorMessage: 'Cannot update the user video rate.' | 46 | errorMessage: 'Cannot update the user video rate.' |
@@ -52,7 +53,7 @@ function rateVideoRetryWrapper (req, res, next) { | |||
52 | }) | 53 | }) |
53 | } | 54 | } |
54 | 55 | ||
55 | function rateVideo (req, res, finalCallback) { | 56 | function rateVideo (req: express.Request, res: express.Response, finalCallback: (err: Error) => void) { |
56 | const rateType = req.body.rating | 57 | const rateType = req.body.rating |
57 | const videoInstance = res.locals.video | 58 | const videoInstance = res.locals.video |
58 | const userInstance = res.locals.oauth.token.User | 59 | const userInstance = res.locals.oauth.token.User |
@@ -168,7 +169,7 @@ function rateVideo (req, res, finalCallback) { | |||
168 | 169 | ||
169 | commitTransaction | 170 | commitTransaction |
170 | 171 | ||
171 | ], function (err, t) { | 172 | ], function (err: Error, t: Sequelize.Transaction) { |
172 | if (err) { | 173 | if (err) { |
173 | // This is just a debug because we will retry the insert | 174 | // This is just a debug because we will retry the insert |
174 | logger.debug('Cannot add the user video rate.', { error: err }) | 175 | logger.debug('Cannot add the user video rate.', { error: err }) |