aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
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
parent4d4e5cd4dca78480ec7f40e747f424cd107376a4 (diff)
downloadPeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.gz
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.tar.zst
PeerTube-69818c9394366b954b6ba3bd697bd9d2b09f2a16.zip
Type functions
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/clients.ts4
-rw-r--r--server/controllers/api/config.ts2
-rw-r--r--server/controllers/api/index.ts2
-rw-r--r--server/controllers/api/pods.ts17
-rw-r--r--server/controllers/api/remote/pods.ts2
-rw-r--r--server/controllers/api/remote/videos.ts40
-rw-r--r--server/controllers/api/requests.ts5
-rw-r--r--server/controllers/api/users.ts22
-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
-rw-r--r--server/controllers/client.ts13
13 files changed, 82 insertions, 72 deletions
diff --git a/server/controllers/api/clients.ts b/server/controllers/api/clients.ts
index f6499556a..8c460096b 100644
--- a/server/controllers/api/clients.ts
+++ b/server/controllers/api/clients.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2 2
3import { CONFIG } from '../../initializers'; 3import { CONFIG } from '../../initializers'
4import { logger } from '../../helpers' 4import { logger } from '../../helpers'
5import { database as db } from '../../initializers/database' 5import { database as db } from '../../initializers/database'
6 6
@@ -9,7 +9,7 @@ const clientsRouter = express.Router()
9clientsRouter.get('/local', getLocalClient) 9clientsRouter.get('/local', getLocalClient)
10 10
11// Get the client credentials for the PeerTube front end 11// Get the client credentials for the PeerTube front end
12function getLocalClient (req, res, next) { 12function getLocalClient (req: express.Request, res: express.Response, next: express.NextFunction) {
13 const serverHostname = CONFIG.WEBSERVER.HOSTNAME 13 const serverHostname = CONFIG.WEBSERVER.HOSTNAME
14 const serverPort = CONFIG.WEBSERVER.PORT 14 const serverPort = CONFIG.WEBSERVER.PORT
15 let headerHostShouldBe = serverHostname 15 let headerHostShouldBe = serverHostname
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 57c9398ec..c63981797 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -7,7 +7,7 @@ const configRouter = express.Router()
7configRouter.get('/', getConfig) 7configRouter.get('/', getConfig)
8 8
9// Get the client credentials for the PeerTube front end 9// Get the client credentials for the PeerTube front end
10function getConfig (req, res, next) { 10function getConfig (req: express.Request, res: express.Response, next: express.NextFunction) {
11 res.json({ 11 res.json({
12 signup: { 12 signup: {
13 enabled: CONFIG.SIGNUP.ENABLED 13 enabled: CONFIG.SIGNUP.ENABLED
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts
index 98004544d..ac3972ac6 100644
--- a/server/controllers/api/index.ts
+++ b/server/controllers/api/index.ts
@@ -28,6 +28,6 @@ export { apiRouter }
28 28
29// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
30 30
31function pong (req, res, next) { 31function pong (req: express.Request, res: express.Response, next: express.NextFunction) {
32 return res.send('pong').status(200).end() 32 return res.send('pong').status(200).end()
33} 33}
diff --git a/server/controllers/api/pods.ts b/server/controllers/api/pods.ts
index a028c4ab9..283105f6c 100644
--- a/server/controllers/api/pods.ts
+++ b/server/controllers/api/pods.ts
@@ -21,6 +21,9 @@ import {
21 setBodyHostPort, 21 setBodyHostPort,
22 setBodyHostsPort 22 setBodyHostsPort
23} from '../../middlewares' 23} from '../../middlewares'
24import {
25 PodInstance
26} from '../../models'
24 27
25const podsRouter = express.Router() 28const podsRouter = express.Router()
26 29
@@ -51,10 +54,10 @@ export {
51 54
52// --------------------------------------------------------------------------- 55// ---------------------------------------------------------------------------
53 56
54function addPods (req, res, next) { 57function addPods (req: express.Request, res: express.Response, next: express.NextFunction) {
55 const informations = req.body 58 const informations = req.body
56 59
57 waterfall([ 60 waterfall<string, Error>([
58 function addPod (callback) { 61 function addPod (callback) {
59 const pod = db.Pod.build(informations) 62 const pod = db.Pod.build(informations)
60 pod.save().asCallback(function (err, podCreated) { 63 pod.save().asCallback(function (err, podCreated) {
@@ -63,7 +66,7 @@ function addPods (req, res, next) {
63 }) 66 })
64 }, 67 },
65 68
66 function sendMyVideos (podCreated, callback) { 69 function sendMyVideos (podCreated: PodInstance, callback) {
67 sendOwnedVideosToPod(podCreated.id) 70 sendOwnedVideosToPod(podCreated.id)
68 71
69 callback(null) 72 callback(null)
@@ -86,7 +89,7 @@ function addPods (req, res, next) {
86 }) 89 })
87} 90}
88 91
89function listPods (req, res, next) { 92function listPods (req: express.Request, res: express.Response, next: express.NextFunction) {
90 db.Pod.list(function (err, podsList) { 93 db.Pod.list(function (err, podsList) {
91 if (err) return next(err) 94 if (err) return next(err)
92 95
@@ -94,8 +97,8 @@ function listPods (req, res, next) {
94 }) 97 })
95} 98}
96 99
97function makeFriendsController (req, res, next) { 100function makeFriendsController (req: express.Request, res: express.Response, next: express.NextFunction) {
98 const hosts = req.body.hosts 101 const hosts = req.body.hosts as string[]
99 102
100 makeFriends(hosts, function (err) { 103 makeFriends(hosts, function (err) {
101 if (err) { 104 if (err) {
@@ -109,7 +112,7 @@ function makeFriendsController (req, res, next) {
109 res.type('json').status(204).end() 112 res.type('json').status(204).end()
110} 113}
111 114
112function quitFriendsController (req, res, next) { 115function quitFriendsController (req: express.Request, res: express.Response, next: express.NextFunction) {
113 quitFriends(function (err) { 116 quitFriends(function (err) {
114 if (err) return next(err) 117 if (err) return next(err)
115 118
diff --git a/server/controllers/api/remote/pods.ts b/server/controllers/api/remote/pods.ts
index 9c9d2164d..b0d6642c1 100644
--- a/server/controllers/api/remote/pods.ts
+++ b/server/controllers/api/remote/pods.ts
@@ -21,7 +21,7 @@ export {
21 21
22// --------------------------------------------------------------------------- 22// ---------------------------------------------------------------------------
23 23
24function removePods (req, res, next) { 24function removePods (req: express.Request, res: express.Response, next: express.NextFunction) {
25 const host = req.body.signature.host 25 const host = req.body.signature.host
26 26
27 waterfall([ 27 waterfall([
diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts
index d97a3db31..d9cc08fb4 100644
--- a/server/controllers/api/remote/videos.ts
+++ b/server/controllers/api/remote/videos.ts
@@ -1,4 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Sequelize from 'sequelize'
2import { eachSeries, waterfall } from 'async' 3import { eachSeries, waterfall } from 'async'
3 4
4import { database as db } from '../../../initializers/database' 5import { database as db } from '../../../initializers/database'
@@ -23,6 +24,7 @@ import {
23 startSerializableTransaction 24 startSerializableTransaction
24} from '../../../helpers' 25} from '../../../helpers'
25import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib' 26import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib'
27import { PodInstance, VideoInstance } from '../../../models'
26 28
27const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] 29const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
28 30
@@ -64,7 +66,7 @@ export {
64 66
65// --------------------------------------------------------------------------- 67// ---------------------------------------------------------------------------
66 68
67function remoteVideos (req, res, next) { 69function remoteVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
68 const requests = req.body.data 70 const requests = req.body.data
69 const fromPod = res.locals.secure.pod 71 const fromPod = res.locals.secure.pod
70 72
@@ -89,7 +91,7 @@ function remoteVideos (req, res, next) {
89 return res.type('json').status(204).end() 91 return res.type('json').status(204).end()
90} 92}
91 93
92function remoteVideosQadu (req, res, next) { 94function remoteVideosQadu (req: express.Request, res: express.Response, next: express.NextFunction) {
93 const requests = req.body.data 95 const requests = req.body.data
94 const fromPod = res.locals.secure.pod 96 const fromPod = res.locals.secure.pod
95 97
@@ -104,7 +106,7 @@ function remoteVideosQadu (req, res, next) {
104 return res.type('json').status(204).end() 106 return res.type('json').status(204).end()
105} 107}
106 108
107function remoteVideosEvents (req, res, next) { 109function remoteVideosEvents (req: express.Request, res: express.Response, next: express.NextFunction) {
108 const requests = req.body.data 110 const requests = req.body.data
109 const fromPod = res.locals.secure.pod 111 const fromPod = res.locals.secure.pod
110 112
@@ -119,7 +121,7 @@ function remoteVideosEvents (req, res, next) {
119 return res.type('json').status(204).end() 121 return res.type('json').status(204).end()
120} 122}
121 123
122function processVideosEventsRetryWrapper (eventData, fromPod, finalCallback) { 124function processVideosEventsRetryWrapper (eventData: any, fromPod: PodInstance, finalCallback: (err: Error) => void) {
123 const options = { 125 const options = {
124 arguments: [ eventData, fromPod ], 126 arguments: [ eventData, fromPod ],
125 errorMessage: 'Cannot process videos events with many retries.' 127 errorMessage: 'Cannot process videos events with many retries.'
@@ -128,7 +130,7 @@ function processVideosEventsRetryWrapper (eventData, fromPod, finalCallback) {
128 retryTransactionWrapper(processVideosEvents, options, finalCallback) 130 retryTransactionWrapper(processVideosEvents, options, finalCallback)
129} 131}
130 132
131function processVideosEvents (eventData, fromPod, finalCallback) { 133function processVideosEvents (eventData: any, fromPod: PodInstance, finalCallback: (err: Error) => void) {
132 waterfall([ 134 waterfall([
133 startSerializableTransaction, 135 startSerializableTransaction,
134 136
@@ -187,7 +189,7 @@ function processVideosEvents (eventData, fromPod, finalCallback) {
187 189
188 commitTransaction 190 commitTransaction
189 191
190 ], function (err, t) { 192 ], function (err: Error, t: Sequelize.Transaction) {
191 if (err) { 193 if (err) {
192 logger.debug('Cannot process a video event.', { error: err }) 194 logger.debug('Cannot process a video event.', { error: err })
193 return rollbackTransaction(err, t, finalCallback) 195 return rollbackTransaction(err, t, finalCallback)
@@ -198,7 +200,7 @@ function processVideosEvents (eventData, fromPod, finalCallback) {
198 }) 200 })
199} 201}
200 202
201function quickAndDirtyUpdateVideoRetryWrapper (videoData, fromPod, finalCallback) { 203function quickAndDirtyUpdateVideoRetryWrapper (videoData: any, fromPod: PodInstance, finalCallback: (err: Error) => void) {
202 const options = { 204 const options = {
203 arguments: [ videoData, fromPod ], 205 arguments: [ videoData, fromPod ],
204 errorMessage: 'Cannot update quick and dirty the remote video with many retries.' 206 errorMessage: 'Cannot update quick and dirty the remote video with many retries.'
@@ -207,7 +209,7 @@ function quickAndDirtyUpdateVideoRetryWrapper (videoData, fromPod, finalCallback
207 retryTransactionWrapper(quickAndDirtyUpdateVideo, options, finalCallback) 209 retryTransactionWrapper(quickAndDirtyUpdateVideo, options, finalCallback)
208} 210}
209 211
210function quickAndDirtyUpdateVideo (videoData, fromPod, finalCallback) { 212function quickAndDirtyUpdateVideo (videoData: any, fromPod: PodInstance, finalCallback: (err: Error) => void) {
211 let videoName 213 let videoName
212 214
213 waterfall([ 215 waterfall([
@@ -243,7 +245,7 @@ function quickAndDirtyUpdateVideo (videoData, fromPod, finalCallback) {
243 245
244 commitTransaction 246 commitTransaction
245 247
246 ], function (err, t) { 248 ], function (err: Error, t: Sequelize.Transaction) {
247 if (err) { 249 if (err) {
248 logger.debug('Cannot quick and dirty update the remote video.', { error: err }) 250 logger.debug('Cannot quick and dirty update the remote video.', { error: err })
249 return rollbackTransaction(err, t, finalCallback) 251 return rollbackTransaction(err, t, finalCallback)
@@ -255,7 +257,7 @@ function quickAndDirtyUpdateVideo (videoData, fromPod, finalCallback) {
255} 257}
256 258
257// Handle retries on fail 259// Handle retries on fail
258function addRemoteVideoRetryWrapper (videoToCreateData, fromPod, finalCallback) { 260function addRemoteVideoRetryWrapper (videoToCreateData: any, fromPod: PodInstance, finalCallback: (err: Error) => void) {
259 const options = { 261 const options = {
260 arguments: [ videoToCreateData, fromPod ], 262 arguments: [ videoToCreateData, fromPod ],
261 errorMessage: 'Cannot insert the remote video with many retries.' 263 errorMessage: 'Cannot insert the remote video with many retries.'
@@ -264,7 +266,7 @@ function addRemoteVideoRetryWrapper (videoToCreateData, fromPod, finalCallback)
264 retryTransactionWrapper(addRemoteVideo, options, finalCallback) 266 retryTransactionWrapper(addRemoteVideo, options, finalCallback)
265} 267}
266 268
267function addRemoteVideo (videoToCreateData, fromPod, finalCallback) { 269function addRemoteVideo (videoToCreateData: any, fromPod: PodInstance, finalCallback: (err: Error) => void) {
268 logger.debug('Adding remote video "%s".', videoToCreateData.remoteId) 270 logger.debug('Adding remote video "%s".', videoToCreateData.remoteId)
269 271
270 waterfall([ 272 waterfall([
@@ -359,7 +361,7 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) {
359 361
360 commitTransaction 362 commitTransaction
361 363
362 ], function (err, t) { 364 ], function (err: Error, t: Sequelize.Transaction) {
363 if (err) { 365 if (err) {
364 // This is just a debug because we will retry the insert 366 // This is just a debug because we will retry the insert
365 logger.debug('Cannot insert the remote video.', { error: err }) 367 logger.debug('Cannot insert the remote video.', { error: err })
@@ -372,7 +374,7 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) {
372} 374}
373 375
374// Handle retries on fail 376// Handle retries on fail
375function updateRemoteVideoRetryWrapper (videoAttributesToUpdate, fromPod, finalCallback) { 377function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: any, fromPod: PodInstance, finalCallback: (err: Error) => void) {
376 const options = { 378 const options = {
377 arguments: [ videoAttributesToUpdate, fromPod ], 379 arguments: [ videoAttributesToUpdate, fromPod ],
378 errorMessage: 'Cannot update the remote video with many retries' 380 errorMessage: 'Cannot update the remote video with many retries'
@@ -381,7 +383,7 @@ function updateRemoteVideoRetryWrapper (videoAttributesToUpdate, fromPod, finalC
381 retryTransactionWrapper(updateRemoteVideo, options, finalCallback) 383 retryTransactionWrapper(updateRemoteVideo, options, finalCallback)
382} 384}
383 385
384function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) { 386function updateRemoteVideo (videoAttributesToUpdate: any, fromPod: PodInstance, finalCallback: (err: Error) => void) {
385 logger.debug('Updating remote video "%s".', videoAttributesToUpdate.remoteId) 387 logger.debug('Updating remote video "%s".', videoAttributesToUpdate.remoteId)
386 388
387 waterfall([ 389 waterfall([
@@ -435,7 +437,7 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) {
435 437
436 commitTransaction 438 commitTransaction
437 439
438 ], function (err, t) { 440 ], function (err: Error, t: Sequelize.Transaction) {
439 if (err) { 441 if (err) {
440 // This is just a debug because we will retry the insert 442 // This is just a debug because we will retry the insert
441 logger.debug('Cannot update the remote video.', { error: err }) 443 logger.debug('Cannot update the remote video.', { error: err })
@@ -447,7 +449,7 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) {
447 }) 449 })
448} 450}
449 451
450function removeRemoteVideo (videoToRemoveData, fromPod, callback) { 452function removeRemoteVideo (videoToRemoveData: any, fromPod: PodInstance, callback: (err: Error) => void) {
451 // We need the instance because we have to remove some other stuffs (thumbnail etc) 453 // We need the instance because we have to remove some other stuffs (thumbnail etc)
452 fetchRemoteVideo(fromPod.host, videoToRemoveData.remoteId, function (err, video) { 454 fetchRemoteVideo(fromPod.host, videoToRemoveData.remoteId, function (err, video) {
453 // Do not return the error, continue the process 455 // Do not return the error, continue the process
@@ -465,7 +467,7 @@ function removeRemoteVideo (videoToRemoveData, fromPod, callback) {
465 }) 467 })
466} 468}
467 469
468function reportAbuseRemoteVideo (reportData, fromPod, callback) { 470function reportAbuseRemoteVideo (reportData: any, fromPod: PodInstance, callback: (err: Error) => void) {
469 fetchOwnedVideo(reportData.videoRemoteId, function (err, video) { 471 fetchOwnedVideo(reportData.videoRemoteId, function (err, video) {
470 if (err || !video) { 472 if (err || !video) {
471 if (!err) err = new Error('video not found') 473 if (!err) err = new Error('video not found')
@@ -494,7 +496,7 @@ function reportAbuseRemoteVideo (reportData, fromPod, callback) {
494 }) 496 })
495} 497}
496 498
497function fetchOwnedVideo (id, callback) { 499function fetchOwnedVideo (id: string, callback: (err: Error, video?: VideoInstance) => void) {
498 db.Video.load(id, function (err, video) { 500 db.Video.load(id, function (err, video) {
499 if (err || !video) { 501 if (err || !video) {
500 if (!err) err = new Error('video not found') 502 if (!err) err = new Error('video not found')
@@ -507,7 +509,7 @@ function fetchOwnedVideo (id, callback) {
507 }) 509 })
508} 510}
509 511
510function fetchRemoteVideo (podHost, remoteId, callback) { 512function fetchRemoteVideo (podHost: string, remoteId: string, callback: (err: Error, video?: VideoInstance) => void) {
511 db.Video.loadByHostAndRemoteId(podHost, remoteId, function (err, video) { 513 db.Video.loadByHostAndRemoteId(podHost, remoteId, function (err, video) {
512 if (err || !video) { 514 if (err || !video) {
513 if (!err) err = new Error('video not found') 515 if (!err) err = new Error('video not found')
diff --git a/server/controllers/api/requests.ts b/server/controllers/api/requests.ts
index ff4b4ac1a..2c18fe046 100644
--- a/server/controllers/api/requests.ts
+++ b/server/controllers/api/requests.ts
@@ -2,6 +2,7 @@ import * as express from 'express'
2import { parallel } from 'async' 2import { parallel } from 'async'
3 3
4import { 4import {
5 BaseRequestScheduler,
5 getRequestScheduler, 6 getRequestScheduler,
6 getRequestVideoQaduScheduler, 7 getRequestVideoQaduScheduler,
7 getRequestVideoEventScheduler 8 getRequestVideoEventScheduler
@@ -24,7 +25,7 @@ export {
24 25
25// --------------------------------------------------------------------------- 26// ---------------------------------------------------------------------------
26 27
27function getStatsRequests (req, res, next) { 28function getStatsRequests (req: express.Request, res: express.Response, next: express.NextFunction) {
28 parallel({ 29 parallel({
29 requestScheduler: buildRequestSchedulerFunction(getRequestScheduler()), 30 requestScheduler: buildRequestSchedulerFunction(getRequestScheduler()),
30 requestVideoQaduScheduler: buildRequestSchedulerFunction(getRequestVideoQaduScheduler()), 31 requestVideoQaduScheduler: buildRequestSchedulerFunction(getRequestVideoQaduScheduler()),
@@ -38,7 +39,7 @@ function getStatsRequests (req, res, next) {
38 39
39// --------------------------------------------------------------------------- 40// ---------------------------------------------------------------------------
40 41
41function buildRequestSchedulerFunction (requestScheduler) { 42function buildRequestSchedulerFunction (requestScheduler: BaseRequestScheduler) {
42 return function (callback) { 43 return function (callback) {
43 requestScheduler.remainingRequestsCount(function (err, count) { 44 requestScheduler.remainingRequestsCount(function (err, count) {
44 if (err) return callback(err) 45 if (err) return callback(err)
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index 44c5ec13c..ffe5881e5 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -76,7 +76,7 @@ export {
76 76
77// --------------------------------------------------------------------------- 77// ---------------------------------------------------------------------------
78 78
79function ensureRegistrationEnabled (req, res, next) { 79function ensureRegistrationEnabled (req: express.Request, res: express.Response, next: express.NextFunction) {
80 const registrationEnabled = CONFIG.SIGNUP.ENABLED 80 const registrationEnabled = CONFIG.SIGNUP.ENABLED
81 81
82 if (registrationEnabled === true) { 82 if (registrationEnabled === true) {
@@ -86,7 +86,7 @@ function ensureRegistrationEnabled (req, res, next) {
86 return res.status(400).send('User registration is not enabled.') 86 return res.status(400).send('User registration is not enabled.')
87} 87}
88 88
89function createUser (req, res, next) { 89function createUser (req: express.Request, res: express.Response, next: express.NextFunction) {
90 const user = db.User.build({ 90 const user = db.User.build({
91 username: req.body.username, 91 username: req.body.username,
92 password: req.body.password, 92 password: req.body.password,
@@ -95,14 +95,14 @@ function createUser (req, res, next) {
95 role: USER_ROLES.USER 95 role: USER_ROLES.USER
96 }) 96 })
97 97
98 user.save().asCallback(function (err, createdUser) { 98 user.save().asCallback(function (err) {
99 if (err) return next(err) 99 if (err) return next(err)
100 100
101 return res.type('json').status(204).end() 101 return res.type('json').status(204).end()
102 }) 102 })
103} 103}
104 104
105function getUserInformation (req, res, next) { 105function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
106 db.User.loadByUsername(res.locals.oauth.token.user.username, function (err, user) { 106 db.User.loadByUsername(res.locals.oauth.token.user.username, function (err, user) {
107 if (err) return next(err) 107 if (err) return next(err)
108 108
@@ -110,9 +110,9 @@ function getUserInformation (req, res, next) {
110 }) 110 })
111} 111}
112 112
113function getUserVideoRating (req, res, next) { 113function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) {
114 const videoId = req.params.videoId 114 const videoId = '' + req.params.videoId
115 const userId = res.locals.oauth.token.User.id 115 const userId = +res.locals.oauth.token.User.id
116 116
117 db.UserVideoRate.load(userId, videoId, null, function (err, ratingObj) { 117 db.UserVideoRate.load(userId, videoId, null, function (err, ratingObj) {
118 if (err) return next(err) 118 if (err) return next(err)
@@ -126,7 +126,7 @@ function getUserVideoRating (req, res, next) {
126 }) 126 })
127} 127}
128 128
129function listUsers (req, res, next) { 129function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) {
130 db.User.listForApi(req.query.start, req.query.count, req.query.sort, function (err, usersList, usersTotal) { 130 db.User.listForApi(req.query.start, req.query.count, req.query.sort, function (err, usersList, usersTotal) {
131 if (err) return next(err) 131 if (err) return next(err)
132 132
@@ -134,7 +134,7 @@ function listUsers (req, res, next) {
134 }) 134 })
135} 135}
136 136
137function removeUser (req, res, next) { 137function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) {
138 waterfall([ 138 waterfall([
139 function loadUser (callback) { 139 function loadUser (callback) {
140 db.User.loadById(req.params.id, callback) 140 db.User.loadById(req.params.id, callback)
@@ -153,7 +153,7 @@ function removeUser (req, res, next) {
153 }) 153 })
154} 154}
155 155
156function updateUser (req, res, next) { 156function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) {
157 db.User.loadByUsername(res.locals.oauth.token.user.username, function (err, user) { 157 db.User.loadByUsername(res.locals.oauth.token.user.username, function (err, user) {
158 if (err) return next(err) 158 if (err) return next(err)
159 159
@@ -168,6 +168,6 @@ function updateUser (req, res, next) {
168 }) 168 })
169} 169}
170 170
171function success (req, res, next) { 171function success (req: express.Request, res: express.Response, next: express.NextFunction) {
172 res.end() 172 res.end()
173} 173}
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 })
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index c3d28245c..503eff750 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -12,6 +12,7 @@ import {
12 STATIC_MAX_AGE 12 STATIC_MAX_AGE
13} from '../initializers' 13} from '../initializers'
14import { root } from '../helpers' 14import { root } from '../helpers'
15import { VideoInstance } from '../models'
15 16
16const clientsRouter = express.Router() 17const clientsRouter = express.Router()
17 18
@@ -25,7 +26,7 @@ const indexPath = join(distPath, 'index.html')
25// Do not use a template engine for a so little thing 26// Do not use a template engine for a so little thing
26clientsRouter.use('/videos/watch/:id', generateWatchHtmlPage) 27clientsRouter.use('/videos/watch/:id', generateWatchHtmlPage)
27 28
28clientsRouter.use('/videos/embed', function (req, res, next) { 29clientsRouter.use('/videos/embed', function (req: express.Request, res: express.Response, next: express.NextFunction) {
29 res.sendFile(embedPath) 30 res.sendFile(embedPath)
30}) 31})
31 32
@@ -33,7 +34,7 @@ clientsRouter.use('/videos/embed', function (req, res, next) {
33clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE })) 34clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE }))
34 35
35// 404 for static files not found 36// 404 for static files not found
36clientsRouter.use('/client/*', function (req, res, next) { 37clientsRouter.use('/client/*', function (req: express.Request, res: express.Response, next: express.NextFunction) {
37 res.sendStatus(404) 38 res.sendStatus(404)
38}) 39})
39 40
@@ -45,7 +46,7 @@ export {
45 46
46// --------------------------------------------------------------------------- 47// ---------------------------------------------------------------------------
47 48
48function addOpenGraphTags (htmlStringPage, video) { 49function addOpenGraphTags (htmlStringPage: string, video: VideoInstance) {
49 let basePreviewUrlHttp 50 let basePreviewUrlHttp
50 51
51 if (video.isOwned()) { 52 if (video.isOwned()) {
@@ -88,8 +89,8 @@ function addOpenGraphTags (htmlStringPage, video) {
88 return htmlStringPage.replace(opengraphComment, tagsString) 89 return htmlStringPage.replace(opengraphComment, tagsString)
89} 90}
90 91
91function generateWatchHtmlPage (req, res, next) { 92function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) {
92 const videoId = req.params.id 93 const videoId = '' + req.params.id
93 94
94 // Let Angular application handle errors 95 // Let Angular application handle errors
95 if (!validator.isUUID(videoId, 4)) return res.sendFile(indexPath) 96 if (!validator.isUUID(videoId, 4)) return res.sendFile(indexPath)
@@ -102,7 +103,7 @@ function generateWatchHtmlPage (req, res, next) {
102 video: function (callback) { 103 video: function (callback) {
103 db.Video.loadAndPopulateAuthorAndPodAndTags(videoId, callback) 104 db.Video.loadAndPopulateAuthorAndPodAndTags(videoId, callback)
104 } 105 }
105 }, function (err, result: any) { 106 }, function (err: Error, result: { file: Buffer, video: VideoInstance }) {
106 if (err) return next(err) 107 if (err) return next(err)
107 108
108 const html = result.file.toString() 109 const html = result.file.toString()