diff options
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/clients.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/config.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/pods.ts | 17 | ||||
-rw-r--r-- | server/controllers/api/remote/pods.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/remote/videos.ts | 40 | ||||
-rw-r--r-- | server/controllers/api/requests.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/users.ts | 22 | ||||
-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 |
12 files changed, 75 insertions, 66 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | 2 | ||
3 | import { CONFIG } from '../../initializers'; | 3 | import { CONFIG } from '../../initializers' |
4 | import { logger } from '../../helpers' | 4 | import { logger } from '../../helpers' |
5 | import { database as db } from '../../initializers/database' | 5 | import { database as db } from '../../initializers/database' |
6 | 6 | ||
@@ -9,7 +9,7 @@ const clientsRouter = express.Router() | |||
9 | clientsRouter.get('/local', getLocalClient) | 9 | clientsRouter.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 |
12 | function getLocalClient (req, res, next) { | 12 | function 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() | |||
7 | configRouter.get('/', getConfig) | 7 | configRouter.get('/', getConfig) |
8 | 8 | ||
9 | // Get the client credentials for the PeerTube front end | 9 | // Get the client credentials for the PeerTube front end |
10 | function getConfig (req, res, next) { | 10 | function 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 | ||
31 | function pong (req, res, next) { | 31 | function 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' |
24 | import { | ||
25 | PodInstance | ||
26 | } from '../../models' | ||
24 | 27 | ||
25 | const podsRouter = express.Router() | 28 | const podsRouter = express.Router() |
26 | 29 | ||
@@ -51,10 +54,10 @@ export { | |||
51 | 54 | ||
52 | // --------------------------------------------------------------------------- | 55 | // --------------------------------------------------------------------------- |
53 | 56 | ||
54 | function addPods (req, res, next) { | 57 | function 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 | ||
89 | function listPods (req, res, next) { | 92 | function 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 | ||
97 | function makeFriendsController (req, res, next) { | 100 | function 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 | ||
112 | function quitFriendsController (req, res, next) { | 115 | function 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 | ||
24 | function removePods (req, res, next) { | 24 | function 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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as Sequelize from 'sequelize' | ||
2 | import { eachSeries, waterfall } from 'async' | 3 | import { eachSeries, waterfall } from 'async' |
3 | 4 | ||
4 | import { database as db } from '../../../initializers/database' | 5 | import { database as db } from '../../../initializers/database' |
@@ -23,6 +24,7 @@ import { | |||
23 | startSerializableTransaction | 24 | startSerializableTransaction |
24 | } from '../../../helpers' | 25 | } from '../../../helpers' |
25 | import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib' | 26 | import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib' |
27 | import { PodInstance, VideoInstance } from '../../../models' | ||
26 | 28 | ||
27 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] | 29 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] |
28 | 30 | ||
@@ -64,7 +66,7 @@ export { | |||
64 | 66 | ||
65 | // --------------------------------------------------------------------------- | 67 | // --------------------------------------------------------------------------- |
66 | 68 | ||
67 | function remoteVideos (req, res, next) { | 69 | function 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 | ||
92 | function remoteVideosQadu (req, res, next) { | 94 | function 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 | ||
107 | function remoteVideosEvents (req, res, next) { | 109 | function 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 | ||
122 | function processVideosEventsRetryWrapper (eventData, fromPod, finalCallback) { | 124 | function 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 | ||
131 | function processVideosEvents (eventData, fromPod, finalCallback) { | 133 | function 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 | ||
201 | function quickAndDirtyUpdateVideoRetryWrapper (videoData, fromPod, finalCallback) { | 203 | function 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 | ||
210 | function quickAndDirtyUpdateVideo (videoData, fromPod, finalCallback) { | 212 | function 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 |
258 | function addRemoteVideoRetryWrapper (videoToCreateData, fromPod, finalCallback) { | 260 | function 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 | ||
267 | function addRemoteVideo (videoToCreateData, fromPod, finalCallback) { | 269 | function 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 |
375 | function updateRemoteVideoRetryWrapper (videoAttributesToUpdate, fromPod, finalCallback) { | 377 | function 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 | ||
384 | function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) { | 386 | function 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 | ||
450 | function removeRemoteVideo (videoToRemoveData, fromPod, callback) { | 452 | function 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 | ||
468 | function reportAbuseRemoteVideo (reportData, fromPod, callback) { | 470 | function 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 | ||
497 | function fetchOwnedVideo (id, callback) { | 499 | function 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 | ||
510 | function fetchRemoteVideo (podHost, remoteId, callback) { | 512 | function 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' | |||
2 | import { parallel } from 'async' | 2 | import { parallel } from 'async' |
3 | 3 | ||
4 | import { | 4 | import { |
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 | ||
27 | function getStatsRequests (req, res, next) { | 28 | function 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 | ||
41 | function buildRequestSchedulerFunction (requestScheduler) { | 42 | function 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 | ||
79 | function ensureRegistrationEnabled (req, res, next) { | 79 | function 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 | ||
89 | function createUser (req, res, next) { | 89 | function 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 | ||
105 | function getUserInformation (req, res, next) { | 105 | function 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 | ||
113 | function getUserVideoRating (req, res, next) { | 113 | function 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 | ||
129 | function listUsers (req, res, next) { | 129 | function 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 | ||
137 | function removeUser (req, res, next) { | 137 | function 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 | ||
156 | function updateUser (req, res, next) { | 156 | function 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 | ||
171 | function success (req, res, next) { | 171 | function 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 @@ | |||
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 }) |