import { join } from 'path'
-import { FILES_CACHE, STATIC_PATHS } from '../../initializers/constants'
+import { FILES_CACHE } 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'
class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
}
async getFilePathImpl (videoUUID: string) {
- const video = await VideoModel.loadByUUIDWithFile(videoUUID)
+ const video = await VideoModel.loadByUUID(videoUUID)
if (!video) return undefined
if (video.isOwned()) return { isOwned: true, path: video.getPreview().getPath() }
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 }
}