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 /server/lib/schedulers/videos-redundancy-scheduler.ts | |
parent | 5e77a5de40ec1dde1008c08aba0e8ec9af02cba6 (diff) | |
download | PeerTube-26649b4215ac68eed5601d9412d2d7ddee98b543.tar.gz PeerTube-26649b4215ac68eed5601d9412d2d7ddee98b543.tar.zst PeerTube-26649b4215ac68eed5601d9412d2d7ddee98b543.zip |
Ensure video existence before duplicating it
Diffstat (limited to 'server/lib/schedulers/videos-redundancy-scheduler.ts')
-rw-r--r-- | server/lib/schedulers/videos-redundancy-scheduler.ts | 25 |
1 files changed, 21 insertions, 4 deletions
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 | ||