diff options
Diffstat (limited to 'server/controllers/api/remote')
-rw-r--r-- | server/controllers/api/remote/videos.ts | 39 |
1 files changed, 20 insertions, 19 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 | } |