]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/cache/videos-preview-cache.ts
Rename Pod -> Server
[github/Chocobozzz/PeerTube.git] / server / lib / cache / videos-preview-cache.ts
index fecdca6eff41c921008f0656465dbd8eae8a75c8..0570f51e8ec624f821f2a7db000a859e9e14c222 100644 (file)
@@ -1,12 +1,10 @@
 import * as asyncLRU from 'async-lru'
 import { join } from 'path'
 import { createWriteStream } from 'fs'
-import * as Promise from 'bluebird'
 
 import { database as db, CONFIG, CACHE } from '../../initializers'
-import { logger, unlinkPromise } from '../../helpers'
+import { logger, unlinkPromise, fetchRemoteVideoPreview } from '../../helpers'
 import { VideoInstance } from '../../models'
-import { fetchRemotePreview } from '../../lib'
 
 class VideosPreviewCache {
 
@@ -43,19 +41,19 @@ class VideosPreviewCache {
     })
   }
 
-  private loadPreviews (key: string) {
-    return db.Video.loadByUUIDAndPopulateAuthorAndPodAndTags(key)
-      .then(video => {
-        if (!video) return undefined
+  private async loadPreviews (key: string) {
+    const video = await db.Video.loadByUUIDAndPopulateAccountAndServerAndTags(key)
+    if (!video) return undefined
 
-        if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName())
+    if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName())
 
-        return this.saveRemotePreviewAndReturnPath(video)
-      })
+    const res = await this.saveRemotePreviewAndReturnPath(video)
+
+    return res
   }
 
   private saveRemotePreviewAndReturnPath (video: VideoInstance) {
-    const req = fetchRemotePreview(video)
+    const req = fetchRemoteVideoPreview(video)
 
     return new Promise<string>((res, rej) => {
       const path = join(CACHE.DIRECTORIES.PREVIEWS, video.getPreviewName())