mirror of https://github.com/Chocobozzz/PeerTube
Ensure video existence before duplicating it
parent
5e77a5de40
commit
26649b4215
|
@ -370,13 +370,15 @@ async function refreshVideoIfNeeded (options: {
|
|||
try {
|
||||
const { response, videoObject } = await fetchRemoteVideo(video.url)
|
||||
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
|
||||
await video.destroy()
|
||||
return 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
|
||||
}
|
||||
|
||||
|
@ -390,8 +392,10 @@ async function refreshVideoIfNeeded (options: {
|
|||
channel: channelActor.VideoChannel,
|
||||
updateViews: options.refreshViews
|
||||
}
|
||||
await retryTransactionWrapper(updateVideoFromAP, updateOptions)
|
||||
await syncVideoExternalAttributes(video, videoObject, options.syncParam)
|
||||
const videoUpdated = await retryTransactionWrapper(updateVideoFromAP, updateOptions)
|
||||
await syncVideoExternalAttributes(videoUpdated, videoObject, options.syncParam)
|
||||
|
||||
return videoUpdated
|
||||
} catch (err) {
|
||||
logger.warn('Cannot refresh video.', { err })
|
||||
return video
|
||||
|
|
|
@ -12,6 +12,7 @@ import { sendCreateCacheFile, sendUpdateCacheFile } from '../activitypub/send'
|
|||
import { VideoModel } from '../../models/video/video'
|
||||
import { getVideoCacheFileActivityPubUrl } from '../activitypub/url'
|
||||
import { removeVideoRedundancy } from '../redundancy'
|
||||
import { getOrCreateVideoAndAccountAndChannel } from '../activitypub'
|
||||
|
||||
export class VideosRedundancyScheduler extends AbstractScheduler {
|
||||
|
||||
|
@ -109,16 +110,32 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
|
|||
const serverActor = await getServerActor()
|
||||
|
||||
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)
|
||||
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
|
||||
}
|
||||
|
||||
// We need more attributes and check if the video still exists
|
||||
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(file.Video.id)
|
||||
if (!video) continue
|
||||
if (!video) {
|
||||
logger.info('Video %s we want to duplicate does not existing anymore, skipping.', file.Video.url)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
logger.info('Duplicating %s - %d in videos redundancy with "%s" strategy.', video.url, file.resolution, redundancy.strategy)
|
||||
|
||||
|
|
Loading…
Reference in New Issue