aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/remote/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/remote/videos.ts')
-rw-r--r--server/controllers/api/remote/videos.ts40
1 files changed, 21 insertions, 19 deletions
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')