diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-10 19:43:21 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-10 19:43:21 +0200 |
commit | 4771e0008dd26eadbb7eaff64255a6ec914fdadb (patch) | |
tree | 4fd58f8a3f3c2d674b936c99817b4f5fb958c5d8 /server | |
parent | 7a214f746bf420defbf17fa218d90d6233551bf8 (diff) | |
download | PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.tar.gz PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.tar.zst PeerTube-4771e0008dd26eadbb7eaff64255a6ec914fdadb.zip |
Better typescript typing for a better world
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/remote/pods.ts | 8 | ||||
-rw-r--r-- | server/controllers/api/remote/videos.ts | 43 | ||||
-rw-r--r-- | server/controllers/api/users.ts | 16 | ||||
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/videos/rate.ts | 23 | ||||
-rw-r--r-- | server/helpers/requests.ts | 18 | ||||
-rw-r--r-- | server/lib/friends.ts | 14 | ||||
-rw-r--r-- | server/lib/request/abstract-request-scheduler.ts | 22 | ||||
-rw-r--r-- | server/lib/request/request-scheduler.ts | 8 | ||||
-rw-r--r-- | server/lib/request/request-video-event-scheduler.ts | 22 | ||||
-rw-r--r-- | server/lib/request/request-video-qadu-scheduler.ts | 31 | ||||
-rw-r--r-- | server/middlewares/secure.ts | 11 | ||||
-rw-r--r-- | server/models/pod/pod-interface.ts | 2 | ||||
-rw-r--r-- | server/models/user/user-interface.ts | 3 | ||||
-rw-r--r-- | server/models/user/user-video-rate-interface.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-abuse-interface.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-blacklist-interface.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-interface.ts | 2 |
19 files changed, 162 insertions, 76 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 | ||
3 | import { database as db } from '../../../initializers/database' | 3 | import { database as db } from '../../../initializers/database' |
4 | import { checkSignature, signatureValidator } from '../../../middlewares' | 4 | import { checkSignature, signatureValidator } from '../../../middlewares' |
5 | import { PodSignature } from '../../../../shared' | ||
5 | 6 | ||
6 | const remotePodsRouter = express.Router() | 7 | const remotePodsRouter = express.Router() |
7 | 8 | ||
@@ -21,12 +22,11 @@ export { | |||
21 | // --------------------------------------------------------------------------- | 22 | // --------------------------------------------------------------------------- |
22 | 23 | ||
23 | function removePods (req: express.Request, res: express.Response, next: express.NextFunction) { | 24 | function 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 { | |||
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) |
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index 845facd55..e79480521 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -17,7 +17,7 @@ import { | |||
17 | setUsersSort, | 17 | setUsersSort, |
18 | token | 18 | token |
19 | } from '../../middlewares' | 19 | } from '../../middlewares' |
20 | import { UserVideoRate as FormatedUserVideoRate } from '../../../shared' | 20 | import { UserVideoRate as FormatedUserVideoRate, UserCreate, UserUpdate } from '../../../shared' |
21 | 21 | ||
22 | const usersRouter = express.Router() | 22 | const usersRouter = express.Router() |
23 | 23 | ||
@@ -78,10 +78,12 @@ export { | |||
78 | // --------------------------------------------------------------------------- | 78 | // --------------------------------------------------------------------------- |
79 | 79 | ||
80 | function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 80 | function createUser (req: express.Request, res: express.Response, next: express.NextFunction) { |
81 | const body: UserCreate = req.body | ||
82 | |||
81 | const user = db.User.build({ | 83 | const user = db.User.build({ |
82 | username: req.body.username, | 84 | username: body.username, |
83 | password: req.body.password, | 85 | password: body.password, |
84 | email: req.body.email, | 86 | email: body.email, |
85 | displayNSFW: false, | 87 | displayNSFW: false, |
86 | role: USER_ROLES.USER | 88 | role: USER_ROLES.USER |
87 | }) | 89 | }) |
@@ -132,10 +134,12 @@ function removeUser (req: express.Request, res: express.Response, next: express. | |||
132 | } | 134 | } |
133 | 135 | ||
134 | function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 136 | function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { |
137 | const body: UserUpdate = req.body | ||
138 | |||
135 | db.User.loadByUsername(res.locals.oauth.token.user.username) | 139 | db.User.loadByUsername(res.locals.oauth.token.user.username) |
136 | .then(user => { | 140 | .then(user => { |
137 | if (req.body.password) user.password = req.body.password | 141 | if (body.password) user.password = body.password |
138 | if (req.body.displayNSFW !== undefined) user.displayNSFW = req.body.displayNSFW | 142 | if (body.displayNSFW !== undefined) user.displayNSFW = body.displayNSFW |
139 | 143 | ||
140 | return user.save() | 144 | return user.save() |
141 | }) | 145 | }) |
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 3b1b7f58e..7d2e3bcfb 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -17,6 +17,7 @@ import { | |||
17 | setPagination | 17 | setPagination |
18 | } from '../../../middlewares' | 18 | } from '../../../middlewares' |
19 | import { VideoInstance } from '../../../models' | 19 | import { VideoInstance } from '../../../models' |
20 | import { VideoAbuseCreate } from '../../../../shared' | ||
20 | 21 | ||
21 | const abuseVideoRouter = express.Router() | 22 | const abuseVideoRouter = express.Router() |
22 | 23 | ||
@@ -63,10 +64,11 @@ function reportVideoAbuseRetryWrapper (req: express.Request, res: express.Respon | |||
63 | function reportVideoAbuse (req: express.Request, res: express.Response) { | 64 | function reportVideoAbuse (req: express.Request, res: express.Response) { |
64 | const videoInstance = res.locals.video | 65 | const videoInstance = res.locals.video |
65 | const reporterUsername = res.locals.oauth.token.User.username | 66 | const reporterUsername = res.locals.oauth.token.User.username |
67 | const body: VideoAbuseCreate = req.body | ||
66 | 68 | ||
67 | const abuse = { | 69 | const abuse = { |
68 | reporterUsername, | 70 | reporterUsername, |
69 | reason: req.body.reason, | 71 | reason: body.reason, |
70 | videoId: videoInstance.id, | 72 | videoId: videoInstance.id, |
71 | reporterPodId: null // This is our pod that reported this abuse | 73 | reporterPodId: null // This is our pod that reported this abuse |
72 | } | 74 | } |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 3532c753e..4ae7ea2ed 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -39,6 +39,7 @@ import { | |||
39 | renamePromise | 39 | renamePromise |
40 | } from '../../../helpers' | 40 | } from '../../../helpers' |
41 | import { TagInstance } from '../../../models' | 41 | import { TagInstance } from '../../../models' |
42 | import { VideoCreate, VideoUpdate } from '../../../../shared' | ||
42 | 43 | ||
43 | import { abuseVideoRouter } from './abuse' | 44 | import { abuseVideoRouter } from './abuse' |
44 | import { blacklistRouter } from './blacklist' | 45 | import { blacklistRouter } from './blacklist' |
@@ -155,7 +156,7 @@ function addVideoRetryWrapper (req: express.Request, res: express.Response, next | |||
155 | } | 156 | } |
156 | 157 | ||
157 | function addVideo (req: express.Request, res: express.Response, videoFile: Express.Multer.File) { | 158 | function addVideo (req: express.Request, res: express.Response, videoFile: Express.Multer.File) { |
158 | const videoInfos = req.body | 159 | const videoInfos: VideoCreate = req.body |
159 | 160 | ||
160 | return db.sequelize.transaction(t => { | 161 | return db.sequelize.transaction(t => { |
161 | const user = res.locals.oauth.token.User | 162 | const user = res.locals.oauth.token.User |
@@ -257,7 +258,7 @@ function updateVideoRetryWrapper (req: express.Request, res: express.Response, n | |||
257 | function updateVideo (req: express.Request, res: express.Response) { | 258 | function updateVideo (req: express.Request, res: express.Response) { |
258 | const videoInstance = res.locals.video | 259 | const videoInstance = res.locals.video |
259 | const videoFieldsSave = videoInstance.toJSON() | 260 | const videoFieldsSave = videoInstance.toJSON() |
260 | const videoInfosToUpdate = req.body | 261 | const videoInfosToUpdate: VideoUpdate = req.body |
261 | 262 | ||
262 | return db.sequelize.transaction(t => { | 263 | return db.sequelize.transaction(t => { |
263 | let tagsPromise: Promise<TagInstance[]> | 264 | let tagsPromise: Promise<TagInstance[]> |
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index dfb5a450f..8456cbaf2 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 Promise from 'bluebird' | ||
2 | 3 | ||
3 | import { database as db } from '../../../initializers/database' | 4 | import { database as db } from '../../../initializers/database' |
4 | import { | 5 | import { |
@@ -18,6 +19,7 @@ import { | |||
18 | authenticate, | 19 | authenticate, |
19 | videoRateValidator | 20 | videoRateValidator |
20 | } from '../../../middlewares' | 21 | } from '../../../middlewares' |
22 | import { UserVideoRateUpdate, VideoRateType } from '../../../../shared' | ||
21 | 23 | ||
22 | const rateVideoRouter = express.Router() | 24 | const rateVideoRouter = express.Router() |
23 | 25 | ||
@@ -47,7 +49,8 @@ function rateVideoRetryWrapper (req: express.Request, res: express.Response, nex | |||
47 | } | 49 | } |
48 | 50 | ||
49 | function rateVideo (req: express.Request, res: express.Response) { | 51 | function rateVideo (req: express.Request, res: express.Response) { |
50 | const rateType = req.body.rating | 52 | const body: UserVideoRateUpdate = req.body |
53 | const rateType = body.rating | ||
51 | const videoInstance = res.locals.video | 54 | const videoInstance = res.locals.video |
52 | const userInstance = res.locals.oauth.token.User | 55 | const userInstance = res.locals.oauth.token.User |
53 | 56 | ||
@@ -62,24 +65,34 @@ function rateVideo (req: express.Request, res: express.Response) { | |||
62 | if (rateType === VIDEO_RATE_TYPES.LIKE) likesToIncrement++ | 65 | if (rateType === VIDEO_RATE_TYPES.LIKE) likesToIncrement++ |
63 | else if (rateType === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement++ | 66 | else if (rateType === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement++ |
64 | 67 | ||
68 | let promise: Promise<any> | ||
69 | |||
65 | // There was a previous rate, update it | 70 | // There was a previous rate, update it |
66 | if (previousRate) { | 71 | if (previousRate) { |
67 | // We will remove the previous rate, so we will need to remove it from the video attribute | 72 | // We will remove the previous rate, so we will need to remove it from the video attribute |
68 | if (previousRate.type === VIDEO_RATE_TYPES.LIKE) likesToIncrement-- | 73 | if (previousRate.type === VIDEO_RATE_TYPES.LIKE) likesToIncrement-- |
69 | else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement-- | 74 | else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement-- |
70 | 75 | ||
71 | previousRate.type = rateType | 76 | if (rateType === 'none') { // Destroy previous rate |
77 | promise = previousRate.destroy() | ||
78 | } else { // Update previous rate | ||
79 | previousRate.type = rateType as VideoRateType | ||
72 | 80 | ||
73 | return previousRate.save(options).then(() => ({ t, likesToIncrement, dislikesToIncrement })) | 81 | promise = previousRate.save() |
74 | } else { // There was not a previous rate, insert a new one | 82 | } |
83 | } else if (rateType !== 'none') { // There was not a previous rate, insert a new one if there is a rate | ||
75 | const query = { | 84 | const query = { |
76 | userId: userInstance.id, | 85 | userId: userInstance.id, |
77 | videoId: videoInstance.id, | 86 | videoId: videoInstance.id, |
78 | type: rateType | 87 | type: rateType |
79 | } | 88 | } |
80 | 89 | ||
81 | return db.UserVideoRate.create(query, options).then(() => ({ likesToIncrement, dislikesToIncrement })) | 90 | promise = db.UserVideoRate.create(query, options) |
91 | } else { | ||
92 | promise = Promise.resolve() | ||
82 | } | 93 | } |
94 | |||
95 | return promise.then(() => ({ likesToIncrement, dislikesToIncrement })) | ||
83 | }) | 96 | }) |
84 | .then(({ likesToIncrement, dislikesToIncrement }) => { | 97 | .then(({ likesToIncrement, dislikesToIncrement }) => { |
85 | const options = { transaction: t } | 98 | const options = { transaction: t } |
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts index 183f6df0d..d67d46044 100644 --- a/server/helpers/requests.ts +++ b/server/helpers/requests.ts | |||
@@ -8,6 +8,7 @@ import { | |||
8 | CONFIG | 8 | CONFIG |
9 | } from '../initializers' | 9 | } from '../initializers' |
10 | import { PodInstance } from '../models' | 10 | import { PodInstance } from '../models' |
11 | import { PodSignature } from '../../shared' | ||
11 | import { sign } from './peertube-crypto' | 12 | import { sign } from './peertube-crypto' |
12 | 13 | ||
13 | type MakeRetryRequestParams = { | 14 | type MakeRetryRequestParams = { |
@@ -37,9 +38,18 @@ type MakeSecureRequestParams = { | |||
37 | } | 38 | } |
38 | function makeSecureRequest (params: MakeSecureRequestParams) { | 39 | function makeSecureRequest (params: MakeSecureRequestParams) { |
39 | return new Promise<{ response: request.RequestResponse, body: any }>((res, rej) => { | 40 | return new Promise<{ response: request.RequestResponse, body: any }>((res, rej) => { |
40 | const requestParams = { | 41 | const requestParams: { |
42 | url: string, | ||
43 | json: { | ||
44 | signature: PodSignature, | ||
45 | data: any | ||
46 | } | ||
47 | } = { | ||
41 | url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path, | 48 | url: REMOTE_SCHEME.HTTP + '://' + params.toPod.host + params.path, |
42 | json: {} | 49 | json: { |
50 | signature: null, | ||
51 | data: null | ||
52 | } | ||
43 | } | 53 | } |
44 | 54 | ||
45 | if (params.method !== 'POST') { | 55 | if (params.method !== 'POST') { |
@@ -58,14 +68,14 @@ function makeSecureRequest (params: MakeSecureRequestParams) { | |||
58 | } | 68 | } |
59 | 69 | ||
60 | sign(dataToSign).then(signature => { | 70 | sign(dataToSign).then(signature => { |
61 | requestParams.json['signature'] = { | 71 | requestParams.json.signature = { |
62 | host, // Which host we pretend to be | 72 | host, // Which host we pretend to be |
63 | signature | 73 | signature |
64 | } | 74 | } |
65 | 75 | ||
66 | // If there are data informations | 76 | // If there are data informations |
67 | if (params.data) { | 77 | if (params.data) { |
68 | requestParams.json['data'] = params.data | 78 | requestParams.json.data = params.data |
69 | } | 79 | } |
70 | 80 | ||
71 | request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body })) | 81 | request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body })) |
diff --git a/server/lib/friends.ts b/server/lib/friends.ts index 3487addbe..4d56e9eb2 100644 --- a/server/lib/friends.ts +++ b/server/lib/friends.ts | |||
@@ -34,7 +34,11 @@ import { | |||
34 | import { | 34 | import { |
35 | RequestEndpoint, | 35 | RequestEndpoint, |
36 | RequestVideoEventType, | 36 | RequestVideoEventType, |
37 | RequestVideoQaduType | 37 | RequestVideoQaduType, |
38 | RemoteVideoCreateData, | ||
39 | RemoteVideoUpdateData, | ||
40 | RemoteVideoRemoveData, | ||
41 | RemoteVideoReportAbuseData | ||
38 | } from '../../shared' | 42 | } from '../../shared' |
39 | 43 | ||
40 | type QaduParam = { videoId: string, type: RequestVideoQaduType } | 44 | type QaduParam = { videoId: string, type: RequestVideoQaduType } |
@@ -52,7 +56,7 @@ function activateSchedulers () { | |||
52 | requestVideoEventScheduler.activate() | 56 | requestVideoEventScheduler.activate() |
53 | } | 57 | } |
54 | 58 | ||
55 | function addVideoToFriends (videoData: Object, transaction: Sequelize.Transaction) { | 59 | function addVideoToFriends (videoData: RemoteVideoCreateData, transaction: Sequelize.Transaction) { |
56 | const options = { | 60 | const options = { |
57 | type: ENDPOINT_ACTIONS.ADD, | 61 | type: ENDPOINT_ACTIONS.ADD, |
58 | endpoint: REQUEST_ENDPOINTS.VIDEOS, | 62 | endpoint: REQUEST_ENDPOINTS.VIDEOS, |
@@ -62,7 +66,7 @@ function addVideoToFriends (videoData: Object, transaction: Sequelize.Transactio | |||
62 | return createRequest(options) | 66 | return createRequest(options) |
63 | } | 67 | } |
64 | 68 | ||
65 | function updateVideoToFriends (videoData: Object, transaction: Sequelize.Transaction) { | 69 | function updateVideoToFriends (videoData: RemoteVideoUpdateData, transaction: Sequelize.Transaction) { |
66 | const options = { | 70 | const options = { |
67 | type: ENDPOINT_ACTIONS.UPDATE, | 71 | type: ENDPOINT_ACTIONS.UPDATE, |
68 | endpoint: REQUEST_ENDPOINTS.VIDEOS, | 72 | endpoint: REQUEST_ENDPOINTS.VIDEOS, |
@@ -72,7 +76,7 @@ function updateVideoToFriends (videoData: Object, transaction: Sequelize.Transac | |||
72 | return createRequest(options) | 76 | return createRequest(options) |
73 | } | 77 | } |
74 | 78 | ||
75 | function removeVideoToFriends (videoParams: Object) { | 79 | function removeVideoToFriends (videoParams: RemoteVideoRemoveData) { |
76 | const options = { | 80 | const options = { |
77 | type: ENDPOINT_ACTIONS.REMOVE, | 81 | type: ENDPOINT_ACTIONS.REMOVE, |
78 | endpoint: REQUEST_ENDPOINTS.VIDEOS, | 82 | endpoint: REQUEST_ENDPOINTS.VIDEOS, |
@@ -82,7 +86,7 @@ function removeVideoToFriends (videoParams: Object) { | |||
82 | return createRequest(options) | 86 | return createRequest(options) |
83 | } | 87 | } |
84 | 88 | ||
85 | function reportAbuseVideoToFriend (reportData: Object, video: VideoInstance, transaction: Sequelize.Transaction) { | 89 | function reportAbuseVideoToFriend (reportData: RemoteVideoReportAbuseData, video: VideoInstance, transaction: Sequelize.Transaction) { |
86 | const options = { | 90 | const options = { |
87 | type: ENDPOINT_ACTIONS.REPORT_ABUSE, | 91 | type: ENDPOINT_ACTIONS.REPORT_ABUSE, |
88 | endpoint: REQUEST_ENDPOINTS.VIDEOS, | 92 | endpoint: REQUEST_ENDPOINTS.VIDEOS, |
diff --git a/server/lib/request/abstract-request-scheduler.ts b/server/lib/request/abstract-request-scheduler.ts index 0a9ff65d5..ce4e2ffd2 100644 --- a/server/lib/request/abstract-request-scheduler.ts +++ b/server/lib/request/abstract-request-scheduler.ts | |||
@@ -10,6 +10,15 @@ import { | |||
10 | REQUESTS_INTERVAL | 10 | REQUESTS_INTERVAL |
11 | } from '../../initializers' | 11 | } from '../../initializers' |
12 | 12 | ||
13 | interface RequestsObjects<U> { | ||
14 | [ id: string ]: { | ||
15 | toPod: PodInstance | ||
16 | endpoint: string | ||
17 | ids: number[] // ids | ||
18 | datas: U[] | ||
19 | } | ||
20 | } | ||
21 | |||
13 | abstract class AbstractRequestScheduler <T> { | 22 | abstract class AbstractRequestScheduler <T> { |
14 | requestInterval: number | 23 | requestInterval: number |
15 | limitPods: number | 24 | limitPods: number |
@@ -27,7 +36,7 @@ abstract class AbstractRequestScheduler <T> { | |||
27 | 36 | ||
28 | abstract getRequestModel (): AbstractRequestClass<T> | 37 | abstract getRequestModel (): AbstractRequestClass<T> |
29 | abstract getRequestToPodModel (): AbstractRequestToPodClass | 38 | abstract getRequestToPodModel (): AbstractRequestToPodClass |
30 | abstract buildRequestObjects (requestsGrouped: T): {} | 39 | abstract buildRequestsObjects (requestsGrouped: T): RequestsObjects<any> |
31 | 40 | ||
32 | activate () { | 41 | activate () { |
33 | logger.info('Requests scheduler activated.') | 42 | logger.info('Requests scheduler activated.') |
@@ -67,7 +76,7 @@ abstract class AbstractRequestScheduler <T> { | |||
67 | // --------------------------------------------------------------------------- | 76 | // --------------------------------------------------------------------------- |
68 | 77 | ||
69 | // Make a requests to friends of a certain type | 78 | // Make a requests to friends of a certain type |
70 | protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: Object) { | 79 | protected makeRequest (toPod: PodInstance, requestEndpoint: string, requestsToMake: any) { |
71 | const params = { | 80 | const params = { |
72 | toPod: toPod, | 81 | toPod: toPod, |
73 | method: 'POST' as 'POST', | 82 | method: 'POST' as 'POST', |
@@ -95,7 +104,7 @@ abstract class AbstractRequestScheduler <T> { | |||
95 | return this.getRequestModel().listWithLimitAndRandom(this.limitPods, this.limitPerPod) | 104 | return this.getRequestModel().listWithLimitAndRandom(this.limitPods, this.limitPerPod) |
96 | .then((requestsGrouped: T) => { | 105 | .then((requestsGrouped: T) => { |
97 | // We want to group requests by destinations pod and endpoint | 106 | // We want to group requests by destinations pod and endpoint |
98 | const requestsToMake = this.buildRequestObjects(requestsGrouped) | 107 | const requestsToMake = this.buildRequestsObjects(requestsGrouped) |
99 | 108 | ||
100 | // If there are no requests, abort | 109 | // If there are no requests, abort |
101 | if (isEmpty(requestsToMake) === true) { | 110 | if (isEmpty(requestsToMake) === true) { |
@@ -105,8 +114,8 @@ abstract class AbstractRequestScheduler <T> { | |||
105 | 114 | ||
106 | logger.info('Making "%s" to friends.', this.description) | 115 | logger.info('Making "%s" to friends.', this.description) |
107 | 116 | ||
108 | const goodPods = [] | 117 | const goodPods: number[] = [] |
109 | const badPods = [] | 118 | const badPods: number[] = [] |
110 | 119 | ||
111 | return Promise.map(Object.keys(requestsToMake), hashKey => { | 120 | return Promise.map(Object.keys(requestsToMake), hashKey => { |
112 | const requestToMake = requestsToMake[hashKey] | 121 | const requestToMake = requestsToMake[hashKey] |
@@ -149,5 +158,6 @@ abstract class AbstractRequestScheduler <T> { | |||
149 | // --------------------------------------------------------------------------- | 158 | // --------------------------------------------------------------------------- |
150 | 159 | ||
151 | export { | 160 | export { |
152 | AbstractRequestScheduler | 161 | AbstractRequestScheduler, |
162 | RequestsObjects | ||
153 | } | 163 | } |
diff --git a/server/lib/request/request-scheduler.ts b/server/lib/request/request-scheduler.ts index 3945ace20..696875dcf 100644 --- a/server/lib/request/request-scheduler.ts +++ b/server/lib/request/request-scheduler.ts | |||
@@ -1,11 +1,11 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | 2 | ||
3 | import { database as db } from '../../initializers/database' | 3 | import { database as db } from '../../initializers/database' |
4 | import { AbstractRequestScheduler } from './abstract-request-scheduler' | 4 | import { AbstractRequestScheduler, RequestsObjects } from './abstract-request-scheduler' |
5 | import { logger } from '../../helpers' | 5 | import { logger } from '../../helpers' |
6 | import { REQUESTS_LIMIT_PODS, REQUESTS_LIMIT_PER_POD } from '../../initializers' | 6 | import { REQUESTS_LIMIT_PODS, REQUESTS_LIMIT_PER_POD } from '../../initializers' |
7 | import { RequestsGrouped } from '../../models' | 7 | import { RequestsGrouped } from '../../models' |
8 | import { RequestEndpoint } from '../../../shared' | 8 | import { RequestEndpoint, RemoteVideoRequest } from '../../../shared' |
9 | 9 | ||
10 | export type RequestSchedulerOptions = { | 10 | export type RequestSchedulerOptions = { |
11 | type: string | 11 | type: string |
@@ -34,8 +34,8 @@ class RequestScheduler extends AbstractRequestScheduler<RequestsGrouped> { | |||
34 | return db.RequestToPod | 34 | return db.RequestToPod |
35 | } | 35 | } |
36 | 36 | ||
37 | buildRequestObjects (requestsGrouped: RequestsGrouped) { | 37 | buildRequestsObjects (requestsGrouped: RequestsGrouped) { |
38 | const requestsToMakeGrouped = {} | 38 | const requestsToMakeGrouped: RequestsObjects<RemoteVideoRequest> = {} |
39 | 39 | ||
40 | Object.keys(requestsGrouped).forEach(toPodId => { | 40 | Object.keys(requestsGrouped).forEach(toPodId => { |
41 | requestsGrouped[toPodId].forEach(data => { | 41 | requestsGrouped[toPodId].forEach(data => { |
diff --git a/server/lib/request/request-video-event-scheduler.ts b/server/lib/request/request-video-event-scheduler.ts index d4d714c02..8a008c51b 100644 --- a/server/lib/request/request-video-event-scheduler.ts +++ b/server/lib/request/request-video-event-scheduler.ts | |||
@@ -1,14 +1,14 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | 2 | ||
3 | import { database as db } from '../../initializers/database' | 3 | import { database as db } from '../../initializers/database' |
4 | import { AbstractRequestScheduler } from './abstract-request-scheduler' | 4 | import { AbstractRequestScheduler, RequestsObjects } from './abstract-request-scheduler' |
5 | import { | 5 | import { |
6 | REQUESTS_VIDEO_EVENT_LIMIT_PODS, | 6 | REQUESTS_VIDEO_EVENT_LIMIT_PODS, |
7 | REQUESTS_VIDEO_EVENT_LIMIT_PER_POD, | 7 | REQUESTS_VIDEO_EVENT_LIMIT_PER_POD, |
8 | REQUEST_VIDEO_EVENT_ENDPOINT | 8 | REQUEST_VIDEO_EVENT_ENDPOINT |
9 | } from '../../initializers' | 9 | } from '../../initializers' |
10 | import { RequestsVideoEventGrouped } from '../../models' | 10 | import { RequestsVideoEventGrouped } from '../../models' |
11 | import { RequestVideoEventType } from '../../../shared' | 11 | import { RequestVideoEventType, RemoteVideoEventRequest, RemoteVideoEventType } from '../../../shared' |
12 | 12 | ||
13 | export type RequestVideoEventSchedulerOptions = { | 13 | export type RequestVideoEventSchedulerOptions = { |
14 | type: RequestVideoEventType | 14 | type: RequestVideoEventType |
@@ -36,8 +36,8 @@ class RequestVideoEventScheduler extends AbstractRequestScheduler<RequestsVideoE | |||
36 | return db.RequestVideoEvent | 36 | return db.RequestVideoEvent |
37 | } | 37 | } |
38 | 38 | ||
39 | buildRequestObjects (eventRequests: RequestsVideoEventGrouped) { | 39 | buildRequestsObjects (eventRequests: RequestsVideoEventGrouped) { |
40 | const requestsToMakeGrouped = {} | 40 | const requestsToMakeGrouped: RequestsObjects<RemoteVideoEventRequest> = {} |
41 | 41 | ||
42 | /* Example: | 42 | /* Example: |
43 | { | 43 | { |
@@ -47,7 +47,15 @@ class RequestVideoEventScheduler extends AbstractRequestScheduler<RequestsVideoE | |||
47 | } | 47 | } |
48 | } | 48 | } |
49 | */ | 49 | */ |
50 | const eventsPerVideoPerPod = {} | 50 | const eventsPerVideoPerPod: { |
51 | [ podId: string ]: { | ||
52 | [ videoRemoteId: string ]: { | ||
53 | views?: number | ||
54 | likes?: number | ||
55 | dislikes?: number | ||
56 | } | ||
57 | } | ||
58 | } = {} | ||
51 | 59 | ||
52 | // We group video events per video and per pod | 60 | // We group video events per video and per pod |
53 | // We add the counts of the same event types | 61 | // We add the counts of the same event types |
@@ -87,8 +95,8 @@ class RequestVideoEventScheduler extends AbstractRequestScheduler<RequestsVideoE | |||
87 | requestsToMakeGrouped[toPodId].datas.push({ | 95 | requestsToMakeGrouped[toPodId].datas.push({ |
88 | data: { | 96 | data: { |
89 | remoteId, | 97 | remoteId, |
90 | eventType, | 98 | eventType: eventType as RemoteVideoEventType, |
91 | count: eventsForVideo[eventType] | 99 | count: +eventsForVideo[eventType] |
92 | } | 100 | } |
93 | }) | 101 | }) |
94 | }) | 102 | }) |
diff --git a/server/lib/request/request-video-qadu-scheduler.ts b/server/lib/request/request-video-qadu-scheduler.ts index 5ec7de9c2..988165170 100644 --- a/server/lib/request/request-video-qadu-scheduler.ts +++ b/server/lib/request/request-video-qadu-scheduler.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | 2 | ||
3 | import { database as db } from '../../initializers/database' | 3 | import { database as db } from '../../initializers/database' |
4 | import { AbstractRequestScheduler } from './abstract-request-scheduler' | 4 | import { AbstractRequestScheduler, RequestsObjects } from './abstract-request-scheduler' |
5 | import { logger } from '../../helpers' | 5 | import { logger } from '../../helpers' |
6 | import { | 6 | import { |
7 | REQUESTS_VIDEO_QADU_LIMIT_PODS, | 7 | REQUESTS_VIDEO_QADU_LIMIT_PODS, |
@@ -9,8 +9,27 @@ import { | |||
9 | REQUEST_VIDEO_QADU_ENDPOINT, | 9 | REQUEST_VIDEO_QADU_ENDPOINT, |
10 | REQUEST_VIDEO_QADU_TYPES | 10 | REQUEST_VIDEO_QADU_TYPES |
11 | } from '../../initializers' | 11 | } from '../../initializers' |
12 | import { RequestsVideoQaduGrouped } from '../../models' | 12 | import { RequestsVideoQaduGrouped, PodInstance } from '../../models' |
13 | import { RequestVideoQaduType } from '../../../shared' | 13 | import { RemoteQaduVideoRequest, RequestVideoQaduType } from '../../../shared' |
14 | |||
15 | // We create a custom interface because we need "videos" attribute for our computations | ||
16 | interface RequestsObjectsCustom<U> extends RequestsObjects<U> { | ||
17 | [ id: string ]: { | ||
18 | toPod: PodInstance | ||
19 | endpoint: string | ||
20 | ids: number[] // ids | ||
21 | datas: U[] | ||
22 | |||
23 | videos: { | ||
24 | [ id: string ]: { | ||
25 | remoteId: string | ||
26 | likes?: number | ||
27 | dislikes?: number | ||
28 | views?: number | ||
29 | } | ||
30 | } | ||
31 | } | ||
32 | } | ||
14 | 33 | ||
15 | export type RequestVideoQaduSchedulerOptions = { | 34 | export type RequestVideoQaduSchedulerOptions = { |
16 | type: RequestVideoQaduType | 35 | type: RequestVideoQaduType |
@@ -37,8 +56,8 @@ class RequestVideoQaduScheduler extends AbstractRequestScheduler<RequestsVideoQa | |||
37 | return db.RequestVideoQadu | 56 | return db.RequestVideoQadu |
38 | } | 57 | } |
39 | 58 | ||
40 | buildRequestObjects (requests: RequestsVideoQaduGrouped) { | 59 | buildRequestsObjects (requests: RequestsVideoQaduGrouped) { |
41 | const requestsToMakeGrouped = {} | 60 | const requestsToMakeGrouped: RequestsObjectsCustom<RemoteQaduVideoRequest> = {} |
42 | 61 | ||
43 | Object.keys(requests).forEach(toPodId => { | 62 | Object.keys(requests).forEach(toPodId => { |
44 | requests[toPodId].forEach(data => { | 63 | requests[toPodId].forEach(data => { |
@@ -59,7 +78,7 @@ class RequestVideoQaduScheduler extends AbstractRequestScheduler<RequestsVideoQa | |||
59 | 78 | ||
60 | // Maybe another attribute was filled for this video | 79 | // Maybe another attribute was filled for this video |
61 | let videoData = requestsToMakeGrouped[hashKey].videos[video.id] | 80 | let videoData = requestsToMakeGrouped[hashKey].videos[video.id] |
62 | if (!videoData) videoData = {} | 81 | if (!videoData) videoData = { remoteId: null } |
63 | 82 | ||
64 | switch (request.type) { | 83 | switch (request.type) { |
65 | case REQUEST_VIDEO_QADU_TYPES.LIKES: | 84 | case REQUEST_VIDEO_QADU_TYPES.LIKES: |
diff --git a/server/middlewares/secure.ts b/server/middlewares/secure.ts index f58bea734..f7424c9c3 100644 --- a/server/middlewares/secure.ts +++ b/server/middlewares/secure.ts | |||
@@ -6,9 +6,12 @@ import { | |||
6 | logger, | 6 | logger, |
7 | checkSignature as peertubeCryptoCheckSignature | 7 | checkSignature as peertubeCryptoCheckSignature |
8 | } from '../helpers' | 8 | } from '../helpers' |
9 | import { PodSignature } from '../../shared' | ||
9 | 10 | ||
10 | function checkSignature (req: express.Request, res: express.Response, next: express.NextFunction) { | 11 | function checkSignature (req: express.Request, res: express.Response, next: express.NextFunction) { |
11 | const host = req.body.signature.host | 12 | const signatureObject: PodSignature = req.body.signature |
13 | const host = signatureObject.host | ||
14 | |||
12 | db.Pod.loadByHost(host) | 15 | db.Pod.loadByHost(host) |
13 | .then(pod => { | 16 | .then(pod => { |
14 | if (pod === null) { | 17 | if (pod === null) { |
@@ -27,7 +30,7 @@ function checkSignature (req: express.Request, res: express.Response, next: expr | |||
27 | signatureShouldBe = host | 30 | signatureShouldBe = host |
28 | } | 31 | } |
29 | 32 | ||
30 | const signatureOk = peertubeCryptoCheckSignature(pod.publicKey, signatureShouldBe, req.body.signature.signature) | 33 | const signatureOk = peertubeCryptoCheckSignature(pod.publicKey, signatureShouldBe, signatureObject.signature) |
31 | 34 | ||
32 | if (signatureOk === true) { | 35 | if (signatureOk === true) { |
33 | res.locals.secure = { | 36 | res.locals.secure = { |
@@ -37,11 +40,11 @@ function checkSignature (req: express.Request, res: express.Response, next: expr | |||
37 | return next() | 40 | return next() |
38 | } | 41 | } |
39 | 42 | ||
40 | logger.error('Signature is not okay in body for %s.', req.body.signature.host) | 43 | logger.error('Signature is not okay in body for %s.', signatureObject.host) |
41 | return res.sendStatus(403) | 44 | return res.sendStatus(403) |
42 | }) | 45 | }) |
43 | .catch(err => { | 46 | .catch(err => { |
44 | logger.error('Cannot get signed host in body.', { error: err.stack, signature: req.body.signature.signature }) | 47 | logger.error('Cannot get signed host in body.', { error: err.stack, signature: signatureObject.signature }) |
45 | return res.sendStatus(500) | 48 | return res.sendStatus(500) |
46 | }) | 49 | }) |
47 | } | 50 | } |
diff --git a/server/models/pod/pod-interface.ts b/server/models/pod/pod-interface.ts index f6963d47e..340d4f1a7 100644 --- a/server/models/pod/pod-interface.ts +++ b/server/models/pod/pod-interface.ts | |||
@@ -2,7 +2,7 @@ import * as Sequelize from 'sequelize' | |||
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | // Don't use barrel, import just what we need | 4 | // Don't use barrel, import just what we need |
5 | import { Pod as FormatedPod } from '../../../shared/models/pod.model' | 5 | import { Pod as FormatedPod } from '../../../shared/models/pods/pod.model' |
6 | 6 | ||
7 | export namespace PodMethods { | 7 | export namespace PodMethods { |
8 | export type ToFormatedJSON = (this: PodInstance) => FormatedPod | 8 | export type ToFormatedJSON = (this: PodInstance) => FormatedPod |
diff --git a/server/models/user/user-interface.ts b/server/models/user/user-interface.ts index f743945f8..9bd3d2ebb 100644 --- a/server/models/user/user-interface.ts +++ b/server/models/user/user-interface.ts | |||
@@ -2,7 +2,8 @@ import * as Sequelize from 'sequelize' | |||
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | // Don't use barrel, import just what we need | 4 | // Don't use barrel, import just what we need |
5 | import { UserRole, User as FormatedUser } from '../../../shared/models/user.model' | 5 | import { User as FormatedUser } from '../../../shared/models/users/user.model' |
6 | import { UserRole } from '../../../shared/models/users/user-role.type' | ||
6 | import { ResultList } from '../../../shared/models/result-list.model' | 7 | import { ResultList } from '../../../shared/models/result-list.model' |
7 | 8 | ||
8 | export namespace UserMethods { | 9 | export namespace UserMethods { |
diff --git a/server/models/user/user-video-rate-interface.ts b/server/models/user/user-video-rate-interface.ts index e0b65a13d..f501f08b7 100644 --- a/server/models/user/user-video-rate-interface.ts +++ b/server/models/user/user-video-rate-interface.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import * as Promise from 'bluebird' | 2 | import * as Promise from 'bluebird' |
3 | 3 | ||
4 | import { VideoRateType } from '../../../shared/models/user-video-rate.model' | 4 | import { VideoRateType } from '../../../shared/models/videos/video-rate.type' |
5 | 5 | ||
6 | export namespace UserVideoRateMethods { | 6 | export namespace UserVideoRateMethods { |
7 | export type Load = (userId: number, videoId: string, transaction: Sequelize.Transaction) => Promise<UserVideoRateInstance> | 7 | export type Load = (userId: number, videoId: string, transaction: Sequelize.Transaction) => Promise<UserVideoRateInstance> |
diff --git a/server/models/video/video-abuse-interface.ts b/server/models/video/video-abuse-interface.ts index 75647fe0e..d6724d36f 100644 --- a/server/models/video/video-abuse-interface.ts +++ b/server/models/video/video-abuse-interface.ts | |||
@@ -5,7 +5,7 @@ import { PodInstance } from '../pod' | |||
5 | import { ResultList } from '../../../shared' | 5 | import { ResultList } from '../../../shared' |
6 | 6 | ||
7 | // Don't use barrel, import just what we need | 7 | // Don't use barrel, import just what we need |
8 | import { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/video-abuse.model' | 8 | import { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/videos/video-abuse.model' |
9 | 9 | ||
10 | export namespace VideoAbuseMethods { | 10 | export namespace VideoAbuseMethods { |
11 | export type ToFormatedJSON = (this: VideoAbuseInstance) => FormatedVideoAbuse | 11 | export type ToFormatedJSON = (this: VideoAbuseInstance) => FormatedVideoAbuse |
diff --git a/server/models/video/video-blacklist-interface.ts b/server/models/video/video-blacklist-interface.ts index 5ca423801..47a510231 100644 --- a/server/models/video/video-blacklist-interface.ts +++ b/server/models/video/video-blacklist-interface.ts | |||
@@ -4,7 +4,7 @@ import * as Promise from 'bluebird' | |||
4 | import { ResultList } from '../../../shared' | 4 | import { ResultList } from '../../../shared' |
5 | 5 | ||
6 | // Don't use barrel, import just what we need | 6 | // Don't use barrel, import just what we need |
7 | import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../../shared/models/video-blacklist.model' | 7 | import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../../shared/models/videos/video-blacklist.model' |
8 | 8 | ||
9 | export namespace BlacklistedVideoMethods { | 9 | export namespace BlacklistedVideoMethods { |
10 | export type ToFormatedJSON = (this: BlacklistedVideoInstance) => FormatedBlacklistedVideo | 10 | export type ToFormatedJSON = (this: BlacklistedVideoInstance) => FormatedBlacklistedVideo |
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts index c3e3365d5..b836d6da6 100644 --- a/server/models/video/video-interface.ts +++ b/server/models/video/video-interface.ts | |||
@@ -5,7 +5,7 @@ import { AuthorInstance } from './author-interface' | |||
5 | import { TagAttributes, TagInstance } from './tag-interface' | 5 | import { TagAttributes, TagInstance } from './tag-interface' |
6 | 6 | ||
7 | // Don't use barrel, import just what we need | 7 | // Don't use barrel, import just what we need |
8 | import { Video as FormatedVideo } from '../../../shared/models/video.model' | 8 | import { Video as FormatedVideo } from '../../../shared/models/videos/video.model' |
9 | import { ResultList } from '../../../shared/models/result-list.model' | 9 | import { ResultList } from '../../../shared/models/result-list.model' |
10 | 10 | ||
11 | export type FormatedAddRemoteVideo = { | 11 | export type FormatedAddRemoteVideo = { |