]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/files-cache/videos-caption-cache.ts
Merge branch 'release/1.4.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / files-cache / videos-caption-cache.ts
index d4a0a33450ed37c4f5e5fea38574b9cb226a6aa1..440c3fde81c2de19c4c763ad0d217e659e4ca4f0 100644 (file)
@@ -4,6 +4,8 @@ import { VideoModel } from '../../models/video/video'
 import { VideoCaptionModel } from '../../models/video/video-caption'
 import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
 import { CONFIG } from '../../initializers/config'
+import { logger } from '../../helpers/logger'
+import { fetchRemoteVideoStaticFile } from '../activitypub'
 
 type GetPathParam = { videoId: string, language: string }
 
@@ -24,13 +26,15 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache <GetPathParam> {
     const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(params.videoId, params.language)
     if (!videoCaption) return undefined
 
-    if (videoCaption.isOwned()) return join(CONFIG.STORAGE.CAPTIONS_DIR, videoCaption.getCaptionName())
+    if (videoCaption.isOwned()) return { isOwned: true, path: join(CONFIG.STORAGE.CAPTIONS_DIR, videoCaption.getCaptionName()) }
 
     const key = params.videoId + VideosCaptionCache.KEY_DELIMITER + params.language
     return this.loadRemoteFile(key)
   }
 
   protected async loadRemoteFile (key: string) {
+    logger.debug('Loading remote caption file %s.', key)
+
     const [ videoId, language ] = key.split(VideosCaptionCache.KEY_DELIMITER)
 
     const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(videoId, language)
@@ -46,7 +50,9 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache <GetPathParam> {
     const remoteStaticPath = videoCaption.getCaptionStaticPath()
     const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName())
 
-    return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath)
+    await fetchRemoteVideoStaticFile(video, remoteStaticPath, destPath)
+
+    return { isOwned: false, path: destPath }
   }
 }