X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Ffiles-cache%2Fvideos-preview-cache.ts;h=a68619d076da9372bd6c6b00ad056d6da6e1b626;hb=b6a1dd4d1b3b0032f8b968e72cbd074f646e8827;hp=01cd3647ea271de4fe228eef687e24e5bdfa813d;hpb=d74d29ad9e35929491cf37223398d2535ab23de0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/files-cache/videos-preview-cache.ts b/server/lib/files-cache/videos-preview-cache.ts index 01cd3647e..a68619d07 100644 --- a/server/lib/files-cache/videos-preview-cache.ts +++ b/server/lib/files-cache/videos-preview-cache.ts @@ -1,7 +1,9 @@ import { join } from 'path' -import { FILES_CACHE, CONFIG, STATIC_PATHS } from '../../initializers' +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 { @@ -15,13 +17,13 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache { return this.instance || (this.instance = new this()) } - async getFilePath (videoUUID: string) { + async getFilePathImpl (videoUUID: string) { const video = await VideoModel.loadByUUIDWithFile(videoUUID) if (!video) return undefined - if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName()) + if (video.isOwned()) return { isOwned: true, path: video.getPreview().getPath() } - return this.loadFromLRU(videoUUID) + return this.loadRemoteFile(videoUUID) } protected async loadRemoteFile (key: string) { @@ -30,10 +32,13 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache { if (video.isOwned()) throw new Error('Cannot load remote preview of owned video.') - const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) - const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, video.getPreviewName()) + // FIXME: use URL + 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 } } }