aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/remote
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/remote')
-rw-r--r--server/controllers/api/remote/pods.ts8
-rw-r--r--server/controllers/api/remote/videos.ts43
2 files changed, 31 insertions, 20 deletions
diff --git a/server/controllers/api/remote/pods.ts b/server/controllers/api/remote/pods.ts
index 6319957d3..69bbd4378 100644
--- a/server/controllers/api/remote/pods.ts
+++ b/server/controllers/api/remote/pods.ts
@@ -2,6 +2,7 @@ import * as express from 'express'
2 2
3import { database as db } from '../../../initializers/database' 3import { database as db } from '../../../initializers/database'
4import { checkSignature, signatureValidator } from '../../../middlewares' 4import { checkSignature, signatureValidator } from '../../../middlewares'
5import { PodSignature } from '../../../../shared'
5 6
6const remotePodsRouter = express.Router() 7const remotePodsRouter = express.Router()
7 8
@@ -21,12 +22,11 @@ export {
21// --------------------------------------------------------------------------- 22// ---------------------------------------------------------------------------
22 23
23function removePods (req: express.Request, res: express.Response, next: express.NextFunction) { 24function removePods (req: express.Request, res: express.Response, next: express.NextFunction) {
24 const host = req.body.signature.host 25 const signature: PodSignature = req.body.signature
26 const host = signature.host
25 27
26 db.Pod.loadByHost(host) 28 db.Pod.loadByHost(host)
27 .then(pod => { 29 .then(pod => pod.destroy())
28 return pod.destroy()
29 })
30 .then(() => res.type('json').status(204).end()) 30 .then(() => res.type('json').status(204).end())
31 .catch(err => next(err)) 31 .catch(err => next(err))
32} 32}
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 {
18import { logger, retryTransactionWrapper } from '../../../helpers' 18import { logger, retryTransactionWrapper } from '../../../helpers'
19import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib' 19import { quickAndDirtyUpdatesVideoToFriends } from '../../../lib'
20import { PodInstance, VideoInstance } from '../../../models' 20import { PodInstance, VideoInstance } from '../../../models'
21import {
22 RemoteVideoRequest,
23 RemoteVideoCreateData,
24 RemoteVideoUpdateData,
25 RemoteVideoRemoveData,
26 RemoteVideoReportAbuseData,
27 RemoteQaduVideoRequest,
28 RemoteQaduVideoData,
29 RemoteVideoEventRequest,
30 RemoteVideoEventData
31} from '../../../../shared'
21 32
22const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] 33const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
23 34
@@ -60,11 +71,11 @@ export {
60// --------------------------------------------------------------------------- 71// ---------------------------------------------------------------------------
61 72
62function remoteVideos (req: express.Request, res: express.Response, next: express.NextFunction) { 73function 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
85function remoteVideosQadu (req: express.Request, res: express.Response, next: express.NextFunction) { 96function 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
99function remoteVideosEvents (req: express.Request, res: express.Response, next: express.NextFunction) { 110function 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
113function processVideosEventsRetryWrapper (eventData: any, fromPod: PodInstance) { 124function 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
122function processVideosEvents (eventData: any, fromPod: PodInstance) { 133function 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
175function quickAndDirtyUpdateVideoRetryWrapper (videoData: any, fromPod: PodInstance) { 186function 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
184function quickAndDirtyUpdateVideo (videoData: any, fromPod: PodInstance) { 195function 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
214function addRemoteVideoRetryWrapper (videoToCreateData: any, fromPod: PodInstance) { 225function 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
223function addRemoteVideo (videoToCreateData: any, fromPod: PodInstance) { 234function 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
296function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: any, fromPod: PodInstance) { 307function 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
305function updateRemoteVideo (videoAttributesToUpdate: any, fromPod: PodInstance) { 316function 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
349function removeRemoteVideo (videoToRemoveData: any, fromPod: PodInstance) { 360function 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
361function reportAbuseRemoteVideo (reportData: any, fromPod: PodInstance) { 372function 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)