diff options
author | Chocobozzz <me@florianbigard.com> | 2018-10-01 10:31:42 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-10-01 10:31:42 +0200 |
commit | 26649b4215ac68eed5601d9412d2d7ddee98b543 (patch) | |
tree | 4edfab19f676bffea7f1c048323b0520ce64b5b3 | |
parent | 5e77a5de40ec1dde1008c08aba0e8ec9af02cba6 (diff) | |
download | PeerTube-26649b4215ac68eed5601d9412d2d7ddee98b543.tar.gz PeerTube-26649b4215ac68eed5601d9412d2d7ddee98b543.tar.zst PeerTube-26649b4215ac68eed5601d9412d2d7ddee98b543.zip |
Ensure video existence before duplicating it
-rw-r--r-- | server/lib/activitypub/videos.ts | 10 | ||||
-rw-r--r-- | server/lib/schedulers/videos-redundancy-scheduler.ts | 25 |
2 files changed, 28 insertions, 7 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 3dccabe12..b1e7f20b9 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -370,13 +370,15 @@ async function refreshVideoIfNeeded (options: { | |||
370 | try { | 370 | try { |
371 | const { response, videoObject } = await fetchRemoteVideo(video.url) | 371 | const { response, videoObject } = await fetchRemoteVideo(video.url) |
372 | if (response.statusCode === 404) { | 372 | if (response.statusCode === 404) { |
373 | logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url) | ||
374 | |||
373 | // Video does not exist anymore | 375 | // Video does not exist anymore |
374 | await video.destroy() | 376 | await video.destroy() |
375 | return undefined | 377 | return undefined |
376 | } | 378 | } |
377 | 379 | ||
378 | if (videoObject === undefined) { | 380 | if (videoObject === undefined) { |
379 | logger.warn('Cannot refresh remote video: invalid body.') | 381 | logger.warn('Cannot refresh remote video %s: invalid body.', video.url) |
380 | return video | 382 | return video |
381 | } | 383 | } |
382 | 384 | ||
@@ -390,8 +392,10 @@ async function refreshVideoIfNeeded (options: { | |||
390 | channel: channelActor.VideoChannel, | 392 | channel: channelActor.VideoChannel, |
391 | updateViews: options.refreshViews | 393 | updateViews: options.refreshViews |
392 | } | 394 | } |
393 | await retryTransactionWrapper(updateVideoFromAP, updateOptions) | 395 | const videoUpdated = await retryTransactionWrapper(updateVideoFromAP, updateOptions) |
394 | await syncVideoExternalAttributes(video, videoObject, options.syncParam) | 396 | await syncVideoExternalAttributes(videoUpdated, videoObject, options.syncParam) |
397 | |||
398 | return videoUpdated | ||
395 | } catch (err) { | 399 | } catch (err) { |
396 | logger.warn('Cannot refresh video.', { err }) | 400 | logger.warn('Cannot refresh video.', { err }) |
397 | return video | 401 | return video |
diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts index d324adfd0..11ee05a53 100644 --- a/server/lib/schedulers/videos-redundancy-scheduler.ts +++ b/server/lib/schedulers/videos-redundancy-scheduler.ts | |||
@@ -12,6 +12,7 @@ import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send' | |||
12 | import { VideoModel } from '../../models/video/video' | 12 | import { VideoModel } from '../../models/video/video' |
13 | import { getVideoCacheFileActivityPubUrl } from '../activitypub/url' | 13 | import { getVideoCacheFileActivityPubUrl } from '../activitypub/url' |
14 | import { removeVideoRedundancy } from '../redundancy' | 14 | import { removeVideoRedundancy } from '../redundancy' |
15 | import { getOrCreateVideoAndAccountAndChannel } from '../activitypub' | ||
15 | 16 | ||
16 | export class VideosRedundancyScheduler extends AbstractScheduler { | 17 | export class VideosRedundancyScheduler extends AbstractScheduler { |
17 | 18 | ||
@@ -109,16 +110,32 @@ export class VideosRedundancyScheduler extends AbstractScheduler { | |||
109 | const serverActor = await getServerActor() | 110 | const serverActor = await getServerActor() |
110 | 111 | ||
111 | for (const file of filesToDuplicate) { | 112 | for (const file of filesToDuplicate) { |
113 | // We need more attributes and check if the video still exists | ||
114 | const getVideoOptions = { | ||
115 | videoObject: file.Video.url, | ||
116 | syncParam: { likes: false, dislikes: false, shares: false, comments: false, thumbnail: false, refreshVideo: true }, | ||
117 | fetchType: 'only-video' as 'only-video' | ||
118 | } | ||
119 | const { video } = await getOrCreateVideoAndAccountAndChannel(getVideoOptions) | ||
120 | |||
112 | const existing = await VideoRedundancyModel.loadLocalByFileId(file.id) | 121 | const existing = await VideoRedundancyModel.loadLocalByFileId(file.id) |
113 | if (existing) { | 122 | if (existing) { |
114 | await this.extendsExpirationOf(existing, redundancy.minLifetime) | 123 | if (video) { |
124 | await this.extendsExpirationOf(existing, redundancy.minLifetime) | ||
125 | } else { | ||
126 | logger.info('Destroying existing redundancy %s, because the associated video does not exist anymore.', existing.url) | ||
127 | |||
128 | await existing.destroy() | ||
129 | } | ||
115 | 130 | ||
116 | continue | 131 | continue |
117 | } | 132 | } |
118 | 133 | ||
119 | // We need more attributes and check if the video still exists | 134 | if (!video) { |
120 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(file.Video.id) | 135 | logger.info('Video %s we want to duplicate does not existing anymore, skipping.', file.Video.url) |
121 | if (!video) continue | 136 | |
137 | continue | ||
138 | } | ||
122 | 139 | ||
123 | logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy) | 140 | logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy) |
124 | 141 | ||