diff options
Diffstat (limited to 'server/controllers/api/remote/videos.ts')
-rw-r--r-- | server/controllers/api/remote/videos.ts | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts index fac85c3a8..96eab6d52 100644 --- a/server/controllers/api/remote/videos.ts +++ b/server/controllers/api/remote/videos.ts | |||
@@ -18,6 +18,17 @@ import { | |||
18 | import { logger, retryTransactionWrapper } from '../../../helpers' | 18 | import { logger, retryTransactionWrapper } from '../../../helpers' |
19 | import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib' | 19 | import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib' |
20 | import { PodInstance, VideoInstance } from '../../../models' | 20 | import { PodInstance, VideoInstance } from '../../../models' |
21 | import { | ||
22 | RemoteVideoRequest, | ||
23 | RemoteVideoCreateData, | ||
24 | RemoteVideoUpdateData, | ||
25 | RemoteVideoRemoveData, | ||
26 | RemoteVideoReportAbuseData, | ||
27 | RemoteQaduVideoRequest, | ||
28 | RemoteQaduVideoData, | ||
29 | RemoteVideoEventRequest, | ||
30 | RemoteVideoEventData | ||
31 | } from '../../../../shared' | ||
21 | 32 | ||
22 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] | 33 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] |
23 | 34 | ||
@@ -60,11 +71,11 @@ export { | |||
60 | // --------------------------------------------------------------------------- | 71 | // --------------------------------------------------------------------------- |
61 | 72 | ||
62 | function remoteVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 73 | function remoteVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
63 | const requests = req.body.data | 74 | const requests: RemoteVideoRequest[] = req.body.data |
64 | const fromPod = res.locals.secure.pod | 75 | const fromPod = res.locals.secure.pod |
65 | 76 | ||
66 | // We need to process in the same order to keep consistency | 77 | // We need to process in the same order to keep consistency |
67 | Promise.each(requests, (request: any) => { | 78 | Promise.each(requests, request => { |
68 | const data = request.data | 79 | const data = request.data |
69 | 80 | ||
70 | // Get the function we need to call in order to process the request | 81 | // Get the function we need to call in order to process the request |
@@ -83,10 +94,10 @@ function remoteVideos (req: express.Request, res: express.Response, next: expres | |||
83 | } | 94 | } |
84 | 95 | ||
85 | function remoteVideosQadu (req: express.Request, res: express.Response, next: express.NextFunction) { | 96 | function remoteVideosQadu (req: express.Request, res: express.Response, next: express.NextFunction) { |
86 | const requests = req.body.data | 97 | const requests: RemoteQaduVideoRequest[] = req.body.data |
87 | const fromPod = res.locals.secure.pod | 98 | const fromPod = res.locals.secure.pod |
88 | 99 | ||
89 | Promise.each(requests, (request: any) => { | 100 | Promise.each(requests, request => { |
90 | const videoData = request.data | 101 | const videoData = request.data |
91 | 102 | ||
92 | return quickAndDirtyUpdateVideoRetryWrapper(videoData, fromPod) | 103 | return quickAndDirtyUpdateVideoRetryWrapper(videoData, fromPod) |
@@ -97,10 +108,10 @@ function remoteVideosQadu (req: express.Request, res: express.Response, next: ex | |||
97 | } | 108 | } |
98 | 109 | ||
99 | function remoteVideosEvents (req: express.Request, res: express.Response, next: express.NextFunction) { | 110 | function remoteVideosEvents (req: express.Request, res: express.Response, next: express.NextFunction) { |
100 | const requests = req.body.data | 111 | const requests: RemoteVideoEventRequest[] = req.body.data |
101 | const fromPod = res.locals.secure.pod | 112 | const fromPod = res.locals.secure.pod |
102 | 113 | ||
103 | Promise.each(requests, (request: any) => { | 114 | Promise.each(requests, request => { |
104 | const eventData = request.data | 115 | const eventData = request.data |
105 | 116 | ||
106 | return processVideosEventsRetryWrapper(eventData, fromPod) | 117 | return processVideosEventsRetryWrapper(eventData, fromPod) |
@@ -110,7 +121,7 @@ function remoteVideosEvents (req: express.Request, res: express.Response, next: | |||
110 | return res.type('json').status(204).end() | 121 | return res.type('json').status(204).end() |
111 | } | 122 | } |
112 | 123 | ||
113 | function processVideosEventsRetryWrapper (eventData: any, fromPod: PodInstance) { | 124 | function processVideosEventsRetryWrapper (eventData: RemoteVideoEventData, fromPod: PodInstance) { |
114 | const options = { | 125 | const options = { |
115 | arguments: [ eventData, fromPod ], | 126 | arguments: [ eventData, fromPod ], |
116 | errorMessage: 'Cannot process videos events with many retries.' | 127 | errorMessage: 'Cannot process videos events with many retries.' |
@@ -119,7 +130,7 @@ function processVideosEventsRetryWrapper (eventData: any, fromPod: PodInstance) | |||
119 | return retryTransactionWrapper(processVideosEvents, options) | 130 | return retryTransactionWrapper(processVideosEvents, options) |
120 | } | 131 | } |
121 | 132 | ||
122 | function processVideosEvents (eventData: any, fromPod: PodInstance) { | 133 | function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) { |
123 | 134 | ||
124 | return db.sequelize.transaction(t => { | 135 | return db.sequelize.transaction(t => { |
125 | return fetchOwnedVideo(eventData.remoteId) | 136 | return fetchOwnedVideo(eventData.remoteId) |
@@ -172,7 +183,7 @@ function processVideosEvents (eventData: any, fromPod: PodInstance) { | |||
172 | }) | 183 | }) |
173 | } | 184 | } |
174 | 185 | ||
175 | function quickAndDirtyUpdateVideoRetryWrapper (videoData: any, fromPod: PodInstance) { | 186 | function quickAndDirtyUpdateVideoRetryWrapper (videoData: RemoteQaduVideoData, fromPod: PodInstance) { |
176 | const options = { | 187 | const options = { |
177 | arguments: [ videoData, fromPod ], | 188 | arguments: [ videoData, fromPod ], |
178 | errorMessage: 'Cannot update quick and dirty the remote video with many retries.' | 189 | errorMessage: 'Cannot update quick and dirty the remote video with many retries.' |
@@ -181,7 +192,7 @@ function quickAndDirtyUpdateVideoRetryWrapper (videoData: any, fromPod: PodInsta | |||
181 | return retryTransactionWrapper(quickAndDirtyUpdateVideo, options) | 192 | return retryTransactionWrapper(quickAndDirtyUpdateVideo, options) |
182 | } | 193 | } |
183 | 194 | ||
184 | function quickAndDirtyUpdateVideo (videoData: any, fromPod: PodInstance) { | 195 | function quickAndDirtyUpdateVideo (videoData: RemoteQaduVideoData, fromPod: PodInstance) { |
185 | let videoName | 196 | let videoName |
186 | 197 | ||
187 | return db.sequelize.transaction(t => { | 198 | return db.sequelize.transaction(t => { |
@@ -211,7 +222,7 @@ function quickAndDirtyUpdateVideo (videoData: any, fromPod: PodInstance) { | |||
211 | } | 222 | } |
212 | 223 | ||
213 | // Handle retries on fail | 224 | // Handle retries on fail |
214 | function addRemoteVideoRetryWrapper (videoToCreateData: any, fromPod: PodInstance) { | 225 | function addRemoteVideoRetryWrapper (videoToCreateData: RemoteVideoCreateData, fromPod: PodInstance) { |
215 | const options = { | 226 | const options = { |
216 | arguments: [ videoToCreateData, fromPod ], | 227 | arguments: [ videoToCreateData, fromPod ], |
217 | errorMessage: 'Cannot insert the remote video with many retries.' | 228 | errorMessage: 'Cannot insert the remote video with many retries.' |
@@ -220,7 +231,7 @@ function addRemoteVideoRetryWrapper (videoToCreateData: any, fromPod: PodInstanc | |||
220 | return retryTransactionWrapper(addRemoteVideo, options) | 231 | return retryTransactionWrapper(addRemoteVideo, options) |
221 | } | 232 | } |
222 | 233 | ||
223 | function addRemoteVideo (videoToCreateData: any, fromPod: PodInstance) { | 234 | function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod: PodInstance) { |
224 | logger.debug('Adding remote video "%s".', videoToCreateData.remoteId) | 235 | logger.debug('Adding remote video "%s".', videoToCreateData.remoteId) |
225 | 236 | ||
226 | return db.sequelize.transaction(t => { | 237 | return db.sequelize.transaction(t => { |
@@ -293,7 +304,7 @@ function addRemoteVideo (videoToCreateData: any, fromPod: PodInstance) { | |||
293 | } | 304 | } |
294 | 305 | ||
295 | // Handle retries on fail | 306 | // Handle retries on fail |
296 | function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: any, fromPod: PodInstance) { | 307 | function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) { |
297 | const options = { | 308 | const options = { |
298 | arguments: [ videoAttributesToUpdate, fromPod ], | 309 | arguments: [ videoAttributesToUpdate, fromPod ], |
299 | errorMessage: 'Cannot update the remote video with many retries' | 310 | errorMessage: 'Cannot update the remote video with many retries' |
@@ -302,7 +313,7 @@ function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: any, fromPod: P | |||
302 | return retryTransactionWrapper(updateRemoteVideo, options) | 313 | return retryTransactionWrapper(updateRemoteVideo, options) |
303 | } | 314 | } |
304 | 315 | ||
305 | function updateRemoteVideo (videoAttributesToUpdate: any, fromPod: PodInstance) { | 316 | function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) { |
306 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.remoteId) | 317 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.remoteId) |
307 | 318 | ||
308 | return db.sequelize.transaction(t => { | 319 | return db.sequelize.transaction(t => { |
@@ -346,7 +357,7 @@ function updateRemoteVideo (videoAttributesToUpdate: any, fromPod: PodInstance) | |||
346 | }) | 357 | }) |
347 | } | 358 | } |
348 | 359 | ||
349 | function removeRemoteVideo (videoToRemoveData: any, fromPod: PodInstance) { | 360 | function removeRemoteVideo (videoToRemoveData: RemoteVideoRemoveData, fromPod: PodInstance) { |
350 | // We need the instance because we have to remove some other stuffs (thumbnail etc) | 361 | // We need the instance because we have to remove some other stuffs (thumbnail etc) |
351 | return fetchRemoteVideo(fromPod.host, videoToRemoveData.remoteId) | 362 | return fetchRemoteVideo(fromPod.host, videoToRemoveData.remoteId) |
352 | .then(video => { | 363 | .then(video => { |
@@ -358,7 +369,7 @@ function removeRemoteVideo (videoToRemoveData: any, fromPod: PodInstance) { | |||
358 | }) | 369 | }) |
359 | } | 370 | } |
360 | 371 | ||
361 | function reportAbuseRemoteVideo (reportData: any, fromPod: PodInstance) { | 372 | function reportAbuseRemoteVideo (reportData: RemoteVideoReportAbuseData, fromPod: PodInstance) { |
362 | return fetchOwnedVideo(reportData.videoRemoteId) | 373 | return fetchOwnedVideo(reportData.videoRemoteId) |
363 | .then(video => { | 374 | .then(video => { |
364 | logger.debug('Reporting remote abuse for video %s.', video.id) | 375 | logger.debug('Reporting remote abuse for video %s.', video.id) |