X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fcache%2Fvideos-preview-cache.ts;h=0570f51e8ec624f821f2a7db000a859e9e14c222;hb=608624252466acf9f1d9ee1c1170bd4fe4d18d18;hp=fecdca6eff41c921008f0656465dbd8eae8a75c8;hpb=72c7248b6fdcdb2175e726ff51b42e7555f2bd84;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/cache/videos-preview-cache.ts b/server/lib/cache/videos-preview-cache.ts index fecdca6ef..0570f51e8 100644 --- a/server/lib/cache/videos-preview-cache.ts +++ b/server/lib/cache/videos-preview-cache.ts @@ -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((res, rej) => { const path = join(CACHE.DIRECTORIES.PREVIEWS, video.getPreviewName())