]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/files-cache/videos-preview-cache.ts
Process remaining segment hashes on live ending
[github/Chocobozzz/PeerTube.git] / server / lib / files-cache / videos-preview-cache.ts
index c117ae426a9df633a58c2bcc1f048811ec43f47e..d0d4fc5b551f4b780aaf86d034624c1b6bacd370 100644 (file)
@@ -1,8 +1,8 @@
 import { join } from 'path'
-import { FILES_CACHE, STATIC_PATHS } from '../../initializers/constants'
+import { FILES_CACHE } from '../../initializers/constants'
 import { VideoModel } from '../../models/video/video'
 import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
-import { CONFIG } from '../../initializers/config'
+import { doRequestAndSaveToFile } from '@server/helpers/requests'
 
 class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
 
@@ -17,10 +17,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 { isOwned: true, path: join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreview().filename) }
+    if (video.isOwned()) return { isOwned: true, path: video.getPreview().getPath() }
 
     return this.loadRemoteFile(videoUUID)
   }
@@ -31,13 +31,13 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
 
     if (video.isOwned()) throw new Error('Cannot load remote preview of owned video.')
 
-    // FIXME: use URL
-    const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreview().filename)
-    const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, video.getPreview().filename)
+    const preview = video.getPreview()
+    const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, preview.filename)
 
-    const path = await this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath)
+    const remoteUrl = preview.getFileUrl(video)
+    await doRequestAndSaveToFile({ uri: remoteUrl }, destPath)
 
-    return { isOwned: false, path }
+    return { isOwned: false, path: destPath }
   }
 }