From ca6d36227a9273f616a462d3aad6a721ab5dd627 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 30 Jan 2020 11:53:38 +0100 Subject: Add url field in caption and use it for thumbnails --- server/lib/files-cache/videos-caption-cache.ts | 7 +++---- server/lib/files-cache/videos-preview-cache.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'server/lib/files-cache') diff --git a/server/lib/files-cache/videos-caption-cache.ts b/server/lib/files-cache/videos-caption-cache.ts index 440c3fde8..26ab3bd0d 100644 --- a/server/lib/files-cache/videos-caption-cache.ts +++ b/server/lib/files-cache/videos-caption-cache.ts @@ -5,7 +5,7 @@ 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' +import { doRequestAndSaveToFile } from '@server/helpers/requests' type GetPathParam = { videoId: string, language: string } @@ -46,11 +46,10 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache { const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId) if (!video) return undefined - // FIXME: use URL - const remoteStaticPath = videoCaption.getCaptionStaticPath() + const remoteUrl = videoCaption.getFileUrl(video) const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName()) - await fetchRemoteVideoStaticFile(video, remoteStaticPath, destPath) + await doRequestAndSaveToFile({ uri: remoteUrl }, destPath) return { isOwned: false, path: destPath } } diff --git a/server/lib/files-cache/videos-preview-cache.ts b/server/lib/files-cache/videos-preview-cache.ts index 3da6bb138..7bfeb5783 100644 --- a/server/lib/files-cache/videos-preview-cache.ts +++ b/server/lib/files-cache/videos-preview-cache.ts @@ -2,8 +2,8 @@ import { join } from 'path' 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' +import { doRequestAndSaveToFile } from '@server/helpers/requests' +import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' class VideosPreviewCache extends AbstractVideoStaticFileCache { @@ -32,11 +32,11 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache { 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) - await fetchRemoteVideoStaticFile(video, remoteStaticPath, destPath) + const remoteUrl = preview.getFileUrl(video) + await doRequestAndSaveToFile({ uri: remoteUrl }, destPath) return { isOwned: false, path: destPath } } -- cgit v1.2.3