aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/files-cache/videos-preview-cache.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-12 16:23:19 +0100
committerChocobozzz <chocobozzz@cpy.re>2021-02-16 10:36:44 +0100
commita8b1b40485145ac1eae513a661d7dd6e0986ce96 (patch)
tree79436a042f1ed350278dd69e365f37ee623aa539 /server/lib/files-cache/videos-preview-cache.ts
parent0472d474fdadd05211fb4f90ce275801db515d08 (diff)
downloadPeerTube-a8b1b40485145ac1eae513a661d7dd6e0986ce96.tar.gz
PeerTube-a8b1b40485145ac1eae513a661d7dd6e0986ce96.tar.zst
PeerTube-a8b1b40485145ac1eae513a661d7dd6e0986ce96.zip
Generate a name for thumbnails
Allows aggressive caching
Diffstat (limited to 'server/lib/files-cache/videos-preview-cache.ts')
-rw-r--r--server/lib/files-cache/videos-preview-cache.ts15
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'
3import { VideoModel } from '../../models/video/video' 3import { VideoModel } from '../../models/video/video'
4import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' 4import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
5import { doRequestAndSaveToFile } from '@server/helpers/requests' 5import { doRequestAndSaveToFile } from '@server/helpers/requests'
6import { ThumbnailModel } from '@server/models/video/thumbnail'
7import { ThumbnailType } from '@shared/models'
8import { logger } from '@server/helpers/logger'
6 9
7class VideosPreviewCache extends AbstractVideoStaticFileCache <string> { 10class 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}