]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/files-cache/videos-preview-cache.ts
Fix tsconfig with CLI tools
[github/Chocobozzz/PeerTube.git] / server / lib / files-cache / videos-preview-cache.ts
index fc0d92c78d29383813ac7afc8f7ccd51b6856ffc..3da6bb1388c5bdf1361c50181357f48316725e9c 100644 (file)
@@ -3,6 +3,7 @@ import { FILES_CACHE, STATIC_PATHS } from '../../initializers/constants'
 import { VideoModel } from '../../models/video/video'
 import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
 import { CONFIG } from '../../initializers/config'
+import { fetchRemoteVideoStaticFile } from '../activitypub'
 
 class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
 
@@ -17,10 +18,10 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
   }
 
   async getFilePathImpl (videoUUID: string) {
-    const video = await VideoModel.loadByUUIDWithFile(videoUUID)
+    const video = await VideoModel.loadByUUID(videoUUID)
     if (!video) return undefined
 
-    if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreview().filename)
+    if (video.isOwned()) return { isOwned: true, path: video.getPreview().getPath() }
 
     return this.loadRemoteFile(videoUUID)
   }
@@ -35,7 +36,9 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
     const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreview().filename)
     const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, video.getPreview().filename)
 
-    return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath)
+    await fetchRemoteVideoStaticFile(video, remoteStaticPath, destPath)
+
+    return { isOwned: false, path: destPath }
   }
 }