diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-11 16:01:56 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-11 16:01:56 +0200 |
commit | 0a6658fdcbd779ada8f3758048c326e997902d5a (patch) | |
tree | 5de40bf901db0299011104b1344783637b964eb0 /server/controllers | |
parent | e6d4b0ff2404dcf0b3a755c3fcc415ffeb6e754d (diff) | |
download | PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.tar.gz PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.tar.zst PeerTube-0a6658fdcbd779ada8f3758048c326e997902d5a.zip |
Use global uuid instead of remoteId for videos
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/remote/videos.ts | 39 | ||||
-rw-r--r-- | server/controllers/api/users.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/abuse.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/rate.ts | 2 | ||||
-rw-r--r-- | server/controllers/client.ts | 13 |
6 files changed, 35 insertions, 27 deletions
diff --git a/server/controllers/api/remote/videos.ts b/server/controllers/api/remote/videos.ts index 96eab6d52..30771d8c4 100644 --- a/server/controllers/api/remote/videos.ts +++ b/server/controllers/api/remote/videos.ts | |||
@@ -133,7 +133,7 @@ function processVideosEventsRetryWrapper (eventData: RemoteVideoEventData, fromP | |||
133 | function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) { | 133 | function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInstance) { |
134 | 134 | ||
135 | return db.sequelize.transaction(t => { | 135 | return db.sequelize.transaction(t => { |
136 | return fetchOwnedVideo(eventData.remoteId) | 136 | return fetchVideoByUUID(eventData.uuid) |
137 | .then(videoInstance => { | 137 | .then(videoInstance => { |
138 | const options = { transaction: t } | 138 | const options = { transaction: t } |
139 | 139 | ||
@@ -176,7 +176,7 @@ function processVideosEvents (eventData: RemoteVideoEventData, fromPod: PodInsta | |||
176 | return quickAndDirtyUpdatesVideoToFriends(qadusParams, t) | 176 | return quickAndDirtyUpdatesVideoToFriends(qadusParams, t) |
177 | }) | 177 | }) |
178 | }) | 178 | }) |
179 | .then(() => logger.info('Remote video event processed for video %s.', eventData.remoteId)) | 179 | .then(() => logger.info('Remote video event processed for video %s.', eventData.uuid)) |
180 | .catch(err => { | 180 | .catch(err => { |
181 | logger.debug('Cannot process a video event.', err) | 181 | logger.debug('Cannot process a video event.', err) |
182 | throw err | 182 | throw err |
@@ -196,7 +196,7 @@ function quickAndDirtyUpdateVideo (videoData: RemoteQaduVideoData, fromPod: PodI | |||
196 | let videoName | 196 | let videoName |
197 | 197 | ||
198 | return db.sequelize.transaction(t => { | 198 | return db.sequelize.transaction(t => { |
199 | return fetchRemoteVideo(fromPod.host, videoData.remoteId) | 199 | return fetchVideoByHostAndUUID(fromPod.host, videoData.uuid) |
200 | .then(videoInstance => { | 200 | .then(videoInstance => { |
201 | const options = { transaction: t } | 201 | const options = { transaction: t } |
202 | 202 | ||
@@ -232,12 +232,12 @@ function addRemoteVideoRetryWrapper (videoToCreateData: RemoteVideoCreateData, f | |||
232 | } | 232 | } |
233 | 233 | ||
234 | function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod: PodInstance) { | 234 | function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod: PodInstance) { |
235 | logger.debug('Adding remote video "%s".', videoToCreateData.remoteId) | 235 | logger.debug('Adding remote video "%s".', videoToCreateData.uuid) |
236 | 236 | ||
237 | return db.sequelize.transaction(t => { | 237 | return db.sequelize.transaction(t => { |
238 | return db.Video.loadByHostAndRemoteId(fromPod.host, videoToCreateData.remoteId) | 238 | return db.Video.loadByUUID(videoToCreateData.uuid) |
239 | .then(video => { | 239 | .then(video => { |
240 | if (video) throw new Error('RemoteId and host pair is not unique.') | 240 | if (video) throw new Error('UUID already exists.') |
241 | 241 | ||
242 | return undefined | 242 | return undefined |
243 | }) | 243 | }) |
@@ -257,7 +257,7 @@ function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod: PodI | |||
257 | .then(({ author, tagInstances }) => { | 257 | .then(({ author, tagInstances }) => { |
258 | const videoData = { | 258 | const videoData = { |
259 | name: videoToCreateData.name, | 259 | name: videoToCreateData.name, |
260 | remoteId: videoToCreateData.remoteId, | 260 | uuid: videoToCreateData.uuid, |
261 | extname: videoToCreateData.extname, | 261 | extname: videoToCreateData.extname, |
262 | infoHash: videoToCreateData.infoHash, | 262 | infoHash: videoToCreateData.infoHash, |
263 | category: videoToCreateData.category, | 263 | category: videoToCreateData.category, |
@@ -272,7 +272,8 @@ function addRemoteVideo (videoToCreateData: RemoteVideoCreateData, fromPod: PodI | |||
272 | updatedAt: videoToCreateData.updatedAt, | 272 | updatedAt: videoToCreateData.updatedAt, |
273 | views: videoToCreateData.views, | 273 | views: videoToCreateData.views, |
274 | likes: videoToCreateData.likes, | 274 | likes: videoToCreateData.likes, |
275 | dislikes: videoToCreateData.dislikes | 275 | dislikes: videoToCreateData.dislikes, |
276 | remote: true | ||
276 | } | 277 | } |
277 | 278 | ||
278 | const video = db.Video.build(videoData) | 279 | const video = db.Video.build(videoData) |
@@ -314,10 +315,10 @@ function updateRemoteVideoRetryWrapper (videoAttributesToUpdate: RemoteVideoUpda | |||
314 | } | 315 | } |
315 | 316 | ||
316 | function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) { | 317 | function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, fromPod: PodInstance) { |
317 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.remoteId) | 318 | logger.debug('Updating remote video "%s".', videoAttributesToUpdate.uuid) |
318 | 319 | ||
319 | return db.sequelize.transaction(t => { | 320 | return db.sequelize.transaction(t => { |
320 | return fetchRemoteVideo(fromPod.host, videoAttributesToUpdate.remoteId) | 321 | return fetchVideoByHostAndUUID(fromPod.host, videoAttributesToUpdate.uuid) |
321 | .then(videoInstance => { | 322 | .then(videoInstance => { |
322 | const tags = videoAttributesToUpdate.tags | 323 | const tags = videoAttributesToUpdate.tags |
323 | 324 | ||
@@ -359,18 +360,18 @@ function updateRemoteVideo (videoAttributesToUpdate: RemoteVideoUpdateData, from | |||
359 | 360 | ||
360 | function removeRemoteVideo (videoToRemoveData: RemoteVideoRemoveData, fromPod: PodInstance) { | 361 | function removeRemoteVideo (videoToRemoveData: RemoteVideoRemoveData, fromPod: PodInstance) { |
361 | // We need the instance because we have to remove some other stuffs (thumbnail etc) | 362 | // We need the instance because we have to remove some other stuffs (thumbnail etc) |
362 | return fetchRemoteVideo(fromPod.host, videoToRemoveData.remoteId) | 363 | return fetchVideoByHostAndUUID(fromPod.host, videoToRemoveData.uuid) |
363 | .then(video => { | 364 | .then(video => { |
364 | logger.debug('Removing remote video %s.', video.remoteId) | 365 | logger.debug('Removing remote video %s.', video.uuid) |
365 | return video.destroy() | 366 | return video.destroy() |
366 | }) | 367 | }) |
367 | .catch(err => { | 368 | .catch(err => { |
368 | logger.debug('Could not fetch remote video.', { host: fromPod.host, remoteId: videoToRemoveData.remoteId, error: err.stack }) | 369 | logger.debug('Could not fetch remote video.', { host: fromPod.host, uuid: videoToRemoveData.uuid, error: err.stack }) |
369 | }) | 370 | }) |
370 | } | 371 | } |
371 | 372 | ||
372 | function reportAbuseRemoteVideo (reportData: RemoteVideoReportAbuseData, fromPod: PodInstance) { | 373 | function reportAbuseRemoteVideo (reportData: RemoteVideoReportAbuseData, fromPod: PodInstance) { |
373 | return fetchOwnedVideo(reportData.videoRemoteId) | 374 | return fetchVideoByUUID(reportData.videoUUID) |
374 | .then(video => { | 375 | .then(video => { |
375 | logger.debug('Reporting remote abuse for video %s.', video.id) | 376 | logger.debug('Reporting remote abuse for video %s.', video.id) |
376 | 377 | ||
@@ -386,8 +387,8 @@ function reportAbuseRemoteVideo (reportData: RemoteVideoReportAbuseData, fromPod | |||
386 | .catch(err => logger.error('Cannot create remote abuse video.', err)) | 387 | .catch(err => logger.error('Cannot create remote abuse video.', err)) |
387 | } | 388 | } |
388 | 389 | ||
389 | function fetchOwnedVideo (id: string) { | 390 | function fetchVideoByUUID (id: string) { |
390 | return db.Video.load(id) | 391 | return db.Video.loadByUUID(id) |
391 | .then(video => { | 392 | .then(video => { |
392 | if (!video) throw new Error('Video not found') | 393 | if (!video) throw new Error('Video not found') |
393 | 394 | ||
@@ -399,15 +400,15 @@ function fetchOwnedVideo (id: string) { | |||
399 | }) | 400 | }) |
400 | } | 401 | } |
401 | 402 | ||
402 | function fetchRemoteVideo (podHost: string, remoteId: string) { | 403 | function fetchVideoByHostAndUUID (podHost: string, uuid: string) { |
403 | return db.Video.loadByHostAndRemoteId(podHost, remoteId) | 404 | return db.Video.loadByHostAndUUID(podHost, uuid) |
404 | .then(video => { | 405 | .then(video => { |
405 | if (!video) throw new Error('Video not found') | 406 | if (!video) throw new Error('Video not found') |
406 | 407 | ||
407 | return video | 408 | return video |
408 | }) | 409 | }) |
409 | .catch(err => { | 410 | .catch(err => { |
410 | logger.error('Cannot load video from host and remote id.', { error: err.stack, podHost, remoteId }) | 411 | logger.error('Cannot load video from host and uuid.', { error: err.stack, podHost, uuid }) |
411 | throw err | 412 | throw err |
412 | }) | 413 | }) |
413 | } | 414 | } |
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index e79480521..6c375cc5b 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -100,7 +100,7 @@ function getUserInformation (req: express.Request, res: express.Response, next: | |||
100 | } | 100 | } |
101 | 101 | ||
102 | function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { | 102 | function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { |
103 | const videoId = '' + req.params.videoId | 103 | const videoId = +req.params.videoId |
104 | const userId = +res.locals.oauth.token.User.id | 104 | const userId = +res.locals.oauth.token.User.id |
105 | 105 | ||
106 | db.UserVideoRate.load(userId, videoId, null) | 106 | db.UserVideoRate.load(userId, videoId, null) |
diff --git a/server/controllers/api/videos/abuse.ts b/server/controllers/api/videos/abuse.ts index 7d2e3bcfb..5cf0303fb 100644 --- a/server/controllers/api/videos/abuse.ts +++ b/server/controllers/api/videos/abuse.ts | |||
@@ -62,7 +62,7 @@ function reportVideoAbuseRetryWrapper (req: express.Request, res: express.Respon | |||
62 | } | 62 | } |
63 | 63 | ||
64 | function reportVideoAbuse (req: express.Request, res: express.Response) { | 64 | function reportVideoAbuse (req: express.Request, res: express.Response) { |
65 | const videoInstance = res.locals.video | 65 | const videoInstance = res.locals.video as VideoInstance |
66 | const reporterUsername = res.locals.oauth.token.User.username | 66 | const reporterUsername = res.locals.oauth.token.User.username |
67 | const body: VideoAbuseCreate = req.body | 67 | const body: VideoAbuseCreate = req.body |
68 | 68 | ||
@@ -81,7 +81,7 @@ function reportVideoAbuse (req: express.Request, res: express.Response) { | |||
81 | const reportData = { | 81 | const reportData = { |
82 | reporterUsername, | 82 | reporterUsername, |
83 | reportReason: abuse.reason, | 83 | reportReason: abuse.reason, |
84 | videoRemoteId: videoInstance.remoteId | 84 | videoUUID: videoInstance.uuid |
85 | } | 85 | } |
86 | 86 | ||
87 | return friends.reportAbuseVideoToFriend(reportData, videoInstance, t).then(() => videoInstance) | 87 | return friends.reportAbuseVideoToFriend(reportData, videoInstance, t).then(() => videoInstance) |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 4ae7ea2ed..e70a5319e 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -176,7 +176,7 @@ function addVideo (req: express.Request, res: express.Response, videoFile: Expre | |||
176 | .then(({ author, tagInstances }) => { | 176 | .then(({ author, tagInstances }) => { |
177 | const videoData = { | 177 | const videoData = { |
178 | name: videoInfos.name, | 178 | name: videoInfos.name, |
179 | remoteId: null, | 179 | remote: false, |
180 | extname: path.extname(videoFile.filename), | 180 | extname: path.extname(videoFile.filename), |
181 | category: videoInfos.category, | 181 | category: videoInfos.category, |
182 | licence: videoInfos.licence, | 182 | licence: videoInfos.licence, |
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts index 8456cbaf2..6ddc69817 100644 --- a/server/controllers/api/videos/rate.ts +++ b/server/controllers/api/videos/rate.ts | |||
@@ -69,7 +69,7 @@ function rateVideo (req: express.Request, res: express.Response) { | |||
69 | 69 | ||
70 | // There was a previous rate, update it | 70 | // There was a previous rate, update it |
71 | if (previousRate) { | 71 | if (previousRate) { |
72 | // 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 update the video count attribute |
73 | if (previousRate.type === VIDEO_RATE_TYPES.LIKE) likesToIncrement-- | 73 | if (previousRate.type === VIDEO_RATE_TYPES.LIKE) likesToIncrement-- |
74 | else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement-- | 74 | else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement-- |
75 | 75 | ||
diff --git a/server/controllers/client.ts b/server/controllers/client.ts index d42e8396d..ac722a578 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts | |||
@@ -78,7 +78,7 @@ function addOpenGraphTags (htmlStringPage: string, video: VideoInstance) { | |||
78 | } | 78 | } |
79 | 79 | ||
80 | let tagsString = '' | 80 | let tagsString = '' |
81 | Object.keys(metaTags).forEach(function (tagName) { | 81 | Object.keys(metaTags).forEach(tagName => { |
82 | const tagValue = metaTags[tagName] | 82 | const tagValue = metaTags[tagName] |
83 | 83 | ||
84 | tagsString += '<meta property="' + tagName + '" content="' + tagValue + '" />' | 84 | tagsString += '<meta property="' + tagName + '" content="' + tagValue + '" />' |
@@ -89,13 +89,20 @@ function addOpenGraphTags (htmlStringPage: string, video: VideoInstance) { | |||
89 | 89 | ||
90 | function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) { | 90 | function generateWatchHtmlPage (req: express.Request, res: express.Response, next: express.NextFunction) { |
91 | const videoId = '' + req.params.id | 91 | const videoId = '' + req.params.id |
92 | let videoPromise: Promise<VideoInstance> | ||
92 | 93 | ||
93 | // Let Angular application handle errors | 94 | // Let Angular application handle errors |
94 | if (!validator.isUUID(videoId, 4)) return res.sendFile(indexPath) | 95 | if (validator.isUUID(videoId, 4)) { |
96 | videoPromise = db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(videoId) | ||
97 | } else if (validator.isInt(videoId)) { | ||
98 | videoPromise = db.Video.loadAndPopulateAuthorAndPodAndTags(+videoId) | ||
99 | } else { | ||
100 | return res.sendFile(indexPath) | ||
101 | } | ||
95 | 102 | ||
96 | Promise.all([ | 103 | Promise.all([ |
97 | readFileBufferPromise(indexPath), | 104 | readFileBufferPromise(indexPath), |
98 | db.Video.loadAndPopulateAuthorAndPodAndTags(videoId) | 105 | videoPromise |
99 | ]) | 106 | ]) |
100 | .then(([ file, video ]) => { | 107 | .then(([ file, video ]) => { |
101 | file = file as Buffer | 108 | file = file as Buffer |