X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Ffiles-cache%2Fvideos-caption-cache.ts;h=440c3fde81c2de19c4c763ad0d217e659e4ca4f0;hb=00aab0666c6f772548c160fdfa871a8843b88f37;hp=0926f400952a37e6738191621de7d9224372de2c;hpb=74dc3bca2b14f5fd3fe80c394dfc34177a46db77;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/files-cache/videos-caption-cache.ts b/server/lib/files-cache/videos-caption-cache.ts index 0926f4009..440c3fde8 100644 --- a/server/lib/files-cache/videos-caption-cache.ts +++ b/server/lib/files-cache/videos-caption-cache.ts @@ -4,6 +4,8 @@ import { VideoModel } from '../../models/video/video' import { VideoCaptionModel } from '../../models/video/video-caption' import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' import { CONFIG } from '../../initializers/config' +import { logger } from '../../helpers/logger' +import { fetchRemoteVideoStaticFile } from '../activitypub' type GetPathParam = { videoId: string, language: string } @@ -20,17 +22,19 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache { return this.instance || (this.instance = new this()) } - async getFilePath (params: GetPathParam) { + async getFilePathImpl (params: GetPathParam) { const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(params.videoId, params.language) if (!videoCaption) return undefined - if (videoCaption.isOwned()) return join(CONFIG.STORAGE.CAPTIONS_DIR, videoCaption.getCaptionName()) + if (videoCaption.isOwned()) return { isOwned: true, path: join(CONFIG.STORAGE.CAPTIONS_DIR, videoCaption.getCaptionName()) } const key = params.videoId + VideosCaptionCache.KEY_DELIMITER + params.language - return this.loadFromLRU(key) + return this.loadRemoteFile(key) } protected async loadRemoteFile (key: string) { + logger.debug('Loading remote caption file %s.', key) + const [ videoId, language ] = key.split(VideosCaptionCache.KEY_DELIMITER) const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(videoId, language) @@ -42,10 +46,13 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache { const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) if (!video) return undefined + // FIXME: use URL const remoteStaticPath = videoCaption.getCaptionStaticPath() const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName()) - return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) + await fetchRemoteVideoStaticFile(video, remoteStaticPath, destPath) + + return { isOwned: false, path: destPath } } }