ActivityPub-federated video streaming platform using P2P directly in your web browser
Ensure video existence before duplicating it
Chocobozzz26649b4215ac
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.tsindex 3dccabe120..b1e7f20b96 100644--- a/server/lib/activitypub/videos.ts+++ b/server/lib/activitypub/videos.ts@@ -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 anymoreawait 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 videodiff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.tsindex d324adfd03..11ee05a537 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'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)