aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-10 22:15:25 +0200
commit69818c9394366b954b6ba3bd697bd9d2b09f2a16 (patch)
treead199a18ec3c322460d6f9523fc383ee562554e0 /server/controllers/api/videos
parent4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff)
downloadPeerTube-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.ts9
-rw-r--r--server/controllers/api/videos/blacklist.ts2
-rw-r--r--server/controllers/api/videos/index.ts29
-rw-r--r--server/controllers/api/videos/rate.ts7
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Sequelize from 'sequelize'
2import { waterfall } from 'async' 3import { waterfall } from 'async'
3 4
4import { database as db } from '../../../initializers/database' 5import { database as db } from '../../../initializers/database'
@@ -46,7 +47,7 @@ export {
46 47
47// --------------------------------------------------------------------------- 48// ---------------------------------------------------------------------------
48 49
49function listVideoAbuses (req, res, next) { 50function 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
57function reportVideoAbuseRetryWrapper (req, res, next) { 58function 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
70function reportVideoAbuse (req, res, finalCallback) { 71function 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
28function addVideoToBlacklist (req, res, next) { 28function 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Sequelize from 'sequelize'
2import * as fs from 'fs' 3import * as fs from 'fs'
3import * as multer from 'multer' 4import * as multer from 'multer'
4import * as path from 'path' 5import * as path from 'path'
@@ -124,21 +125,21 @@ export {
124 125
125// --------------------------------------------------------------------------- 126// ---------------------------------------------------------------------------
126 127
127function listVideoCategories (req, res, next) { 128function listVideoCategories (req: express.Request, res: express.Response, next: express.NextFunction) {
128 res.json(VIDEO_CATEGORIES) 129 res.json(VIDEO_CATEGORIES)
129} 130}
130 131
131function listVideoLicences (req, res, next) { 132function listVideoLicences (req: express.Request, res: express.Response, next: express.NextFunction) {
132 res.json(VIDEO_LICENCES) 133 res.json(VIDEO_LICENCES)
133} 134}
134 135
135function listVideoLanguages (req, res, next) { 136function 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
141function addVideoRetryWrapper (req, res, next) { 142function 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
155function addVideo (req, res, videoFile, finalCallback) { 156function 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
269function updateVideoRetryWrapper (req, res, next) { 270function 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
283function updateVideo (req, res, finalCallback) { 284function 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
364function getVideo (req, res, next) { 365function 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
396function listVideos (req, res, next) { 397function 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
404function removeVideo (req, res, next) { 405function 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
417function searchVideos (req, res, next) { 418function 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Sequelize from 'sequelize'
2import { waterfall } from 'async' 3import { waterfall } from 'async'
3 4
4import { database as db } from '../../../initializers/database' 5import { database as db } from '../../../initializers/database'
@@ -39,7 +40,7 @@ export {
39 40
40// --------------------------------------------------------------------------- 41// ---------------------------------------------------------------------------
41 42
42function rateVideoRetryWrapper (req, res, next) { 43function 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
55function rateVideo (req, res, finalCallback) { 56function 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 })