diff options
Diffstat (limited to 'server/lib/files-cache')
-rw-r--r-- | server/lib/files-cache/videos-preview-cache.ts | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/server/lib/files-cache/videos-preview-cache.ts b/server/lib/files-cache/videos-preview-cache.ts index d0d4fc5b5..51146d718 100644 --- a/server/lib/files-cache/videos-preview-cache.ts +++ b/server/lib/files-cache/videos-preview-cache.ts | |||
@@ -3,6 +3,9 @@ import { FILES_CACHE } from '../../initializers/constants' | |||
3 | import { VideoModel } from '../../models/video/video' | 3 | import { VideoModel } from '../../models/video/video' |
4 | import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' | 4 | import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' |
5 | import { doRequestAndSaveToFile } from '@server/helpers/requests' | 5 | import { doRequestAndSaveToFile } from '@server/helpers/requests' |
6 | import { ThumbnailModel } from '@server/models/video/thumbnail' | ||
7 | import { ThumbnailType } from '@shared/models' | ||
8 | import { logger } from '@server/helpers/logger' | ||
6 | 9 | ||
7 | class VideosPreviewCache extends AbstractVideoStaticFileCache <string> { | 10 | class VideosPreviewCache extends AbstractVideoStaticFileCache <string> { |
8 | 11 | ||
@@ -16,13 +19,13 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache <string> { | |||
16 | return this.instance || (this.instance = new this()) | 19 | return this.instance || (this.instance = new this()) |
17 | } | 20 | } |
18 | 21 | ||
19 | async getFilePathImpl (videoUUID: string) { | 22 | async getFilePathImpl (filename: string) { |
20 | const video = await VideoModel.loadByUUID(videoUUID) | 23 | const thumbnail = await ThumbnailModel.loadWithVideoByName(filename, ThumbnailType.PREVIEW) |
21 | if (!video) return undefined | 24 | if (!thumbnail) return undefined |
22 | 25 | ||
23 | if (video.isOwned()) return { isOwned: true, path: video.getPreview().getPath() } | 26 | if (thumbnail.Video.isOwned()) return { isOwned: true, path: thumbnail.getPath() } |
24 | 27 | ||
25 | return this.loadRemoteFile(videoUUID) | 28 | return this.loadRemoteFile(thumbnail.Video.uuid) |
26 | } | 29 | } |
27 | 30 | ||
28 | protected async loadRemoteFile (key: string) { | 31 | protected async loadRemoteFile (key: string) { |
@@ -37,6 +40,8 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache <string> { | |||
37 | const remoteUrl = preview.getFileUrl(video) | 40 | const remoteUrl = preview.getFileUrl(video) |
38 | await doRequestAndSaveToFile({ uri: remoteUrl }, destPath) | 41 | await doRequestAndSaveToFile({ uri: remoteUrl }, destPath) |
39 | 42 | ||
43 | logger.debug('Fetched remote preview %s to %s.', remoteUrl, destPath) | ||
44 | |||
40 | return { isOwned: false, path: destPath } | 45 | return { isOwned: false, path: destPath } |
41 | } | 46 | } |
42 | } | 47 | } |