aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/thumbnail.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/thumbnail.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/thumbnail.ts')
-rw-r--r--server/lib/thumbnail.ts18
1 files changed, 14 insertions, 4 deletions
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts
index dc86423f8..740b83acb 100644
--- a/server/lib/thumbnail.ts
+++ b/server/lib/thumbnail.ts
@@ -27,18 +27,28 @@ function createPlaylistMiniatureFromExisting (
27 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail }) 27 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail })
28} 28}
29 29
30function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: MVideoPlaylistThumbnail, size?: ImageSize) { 30function createPlaylistMiniatureFromUrl (downloadUrl: string, playlist: MVideoPlaylistThumbnail, size?: ImageSize) {
31 const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) 31 const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size)
32 const type = ThumbnailType.MINIATURE 32 const type = ThumbnailType.MINIATURE
33 33
34 const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height }) 34 // Only save the file URL if it is a remote playlist
35 const fileUrl = playlist.isOwned()
36 ? null
37 : downloadUrl
38
39 const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height })
35 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) 40 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
36} 41}
37 42
38function createVideoMiniatureFromUrl (fileUrl: string, video: MVideoThumbnail, type: ThumbnailType, size?: ImageSize) { 43function createVideoMiniatureFromUrl (downloadUrl: string, video: MVideoThumbnail, type: ThumbnailType, size?: ImageSize) {
39 const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) 44 const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
40 const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height })
41 45
46 // Only save the file URL if it is a remote video
47 const fileUrl = video.isOwned()
48 ? null
49 : downloadUrl
50
51 const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height })
42 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) 52 return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
43} 53}
44 54