Ensure video existence before duplicating it
This commit is contained in:
parent
5e77a5de40
commit
26649b4215
|
@ -370,13 +370,15 @@ async function refreshVideoIfNeeded (options: {
|
||||||
try {
|
try {
|
||||||
const { response, videoObject } = await fetchRemoteVideo(video.url)
|
const { response, videoObject } = await fetchRemoteVideo(video.url)
|
||||||
if (response.statusCode === 404) {
|
if (response.statusCode === 404) {
|
||||||
|
logger.info('Cannot refresh remote video %s: video does not exist anymore. Deleting it.', video.url)
|
||||||
|
|
||||||
// Video does not exist anymore
|
// Video does not exist anymore
|
||||||
await video.destroy()
|
await video.destroy()
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
if (videoObject === undefined) {
|
if (videoObject === undefined) {
|
||||||
logger.warn('Cannot refresh remote video: invalid body.')
|
logger.warn('Cannot refresh remote video %s: invalid body.', video.url)
|
||||||
return video
|
return video
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,8 +392,10 @@ async function refreshVideoIfNeeded (options: {
|
||||||
channel: channelActor.VideoChannel,
|
channel: channelActor.VideoChannel,
|
||||||
updateViews: options.refreshViews
|
updateViews: options.refreshViews
|
||||||
}
|
}
|
||||||
await retryTransactionWrapper(updateVideoFromAP, updateOptions)
|
const videoUpdated = await retryTransactionWrapper(updateVideoFromAP, updateOptions)
|
||||||
await syncVideoExternalAttributes(video, videoObject, options.syncParam)
|
await syncVideoExternalAttributes(videoUpdated, videoObject, options.syncParam)
|
||||||
|
|
||||||
|
return videoUpdated
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn('Cannot refresh video.', { err })
|
logger.warn('Cannot refresh video.', { err })
|
||||||
return video
|
return video
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send'
|
||||||
import { VideoModel } from '../../models/video/video'
|
import { VideoModel } from '../../models/video/video'
|
||||||
import { getVideoCacheFileActivityPubUrl } from '../activitypub/url'
|
import { getVideoCacheFileActivityPubUrl } from '../activitypub/url'
|
||||||
import { removeVideoRedundancy } from '../redundancy'
|
import { removeVideoRedundancy } from '../redundancy'
|
||||||
|
import { getOrCreateVideoAndAccountAndChannel } from '../activitypub'
|
||||||
|
|
||||||
export class VideosRedundancyScheduler extends AbstractScheduler {
|
export class VideosRedundancyScheduler extends AbstractScheduler {
|
||||||
|
|
||||||
|
@ -109,16 +110,32 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
|
||||||
const serverActor = await getServerActor()
|
const serverActor = await getServerActor()
|
||||||
|
|
||||||
for (const file of filesToDuplicate) {
|
for (const file of filesToDuplicate) {
|
||||||
|
// We need more attributes and check if the video still exists
|
||||||
|
const getVideoOptions = {
|
||||||
|
videoObject: file.Video.url,
|
||||||
|
syncParam: { likes: false, dislikes: false, shares: false, comments: false, thumbnail: false, refreshVideo: true },
|
||||||
|
fetchType: 'only-video' as 'only-video'
|
||||||
|
}
|
||||||
|
const { video } = await getOrCreateVideoAndAccountAndChannel(getVideoOptions)
|
||||||
|
|
||||||
const existing = await VideoRedundancyModel.loadLocalByFileId(file.id)
|
const existing = await VideoRedundancyModel.loadLocalByFileId(file.id)
|
||||||
if (existing) {
|
if (existing) {
|
||||||
await this.extendsExpirationOf(existing, redundancy.minLifetime)
|
if (video) {
|
||||||
|
await this.extendsExpirationOf(existing, redundancy.minLifetime)
|
||||||
|
} else {
|
||||||
|
logger.info('Destroying existing redundancy %s, because the associated video does not exist anymore.', existing.url)
|
||||||
|
|
||||||
|
await existing.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need more attributes and check if the video still exists
|
if (!video) {
|
||||||
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(file.Video.id)
|
logger.info('Video %s we want to duplicate does not existing anymore, skipping.', file.Video.url)
|
||||||
if (!video) continue
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy)
|
logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue