diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/playlist.ts | 3 | ||||
-rw-r--r-- | server/lib/thumbnail.ts | 26 |
2 files changed, 23 insertions, 6 deletions
diff --git a/server/lib/activitypub/playlist.ts b/server/lib/activitypub/playlist.ts index 36a91faec..f569d881c 100644 --- a/server/lib/activitypub/playlist.ts +++ b/server/lib/activitypub/playlist.ts | |||
@@ -105,6 +105,9 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc | |||
105 | } catch (err) { | 105 | } catch (err) { |
106 | logger.warn('Cannot generate thumbnail of %s.', playlistObject.id, { err }) | 106 | logger.warn('Cannot generate thumbnail of %s.', playlistObject.id, { err }) |
107 | } | 107 | } |
108 | } else if (refreshedPlaylist.hasThumbnail()) { | ||
109 | await refreshedPlaylist.Thumbnail.destroy() | ||
110 | refreshedPlaylist.Thumbnail = null | ||
108 | } | 111 | } |
109 | 112 | ||
110 | return resetVideoPlaylistElements(accItems, refreshedPlaylist) | 113 | return resetVideoPlaylistElements(accItems, refreshedPlaylist) |
diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 18bdcded4..a59773f5a 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts | |||
@@ -12,12 +12,18 @@ import { VideoPlaylistModel } from '../models/video/video-playlist' | |||
12 | 12 | ||
13 | type ImageSize = { height: number, width: number } | 13 | type ImageSize = { height: number, width: number } |
14 | 14 | ||
15 | function createPlaylistMiniatureFromExisting (inputPath: string, playlist: VideoPlaylistModel, keepOriginal = false, size?: ImageSize) { | 15 | function createPlaylistMiniatureFromExisting ( |
16 | inputPath: string, | ||
17 | playlist: VideoPlaylistModel, | ||
18 | automaticallyGenerated: boolean, | ||
19 | keepOriginal = false, | ||
20 | size?: ImageSize | ||
21 | ) { | ||
16 | const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) | 22 | const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) |
17 | const type = ThumbnailType.MINIATURE | 23 | const type = ThumbnailType.MINIATURE |
18 | 24 | ||
19 | const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) | 25 | const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal) |
20 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) | 26 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail }) |
21 | } | 27 | } |
22 | 28 | ||
23 | function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: VideoPlaylistModel, size?: ImageSize) { | 29 | function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: VideoPlaylistModel, size?: ImageSize) { |
@@ -35,11 +41,17 @@ function createVideoMiniatureFromUrl (fileUrl: string, video: VideoModel, type: | |||
35 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) | 41 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) |
36 | } | 42 | } |
37 | 43 | ||
38 | function createVideoMiniatureFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) { | 44 | function createVideoMiniatureFromExisting ( |
45 | inputPath: string, | ||
46 | video: VideoModel, | ||
47 | type: ThumbnailType, | ||
48 | automaticallyGenerated: boolean, | ||
49 | size?: ImageSize | ||
50 | ) { | ||
39 | const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) | 51 | const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) |
40 | const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }) | 52 | const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }) |
41 | 53 | ||
42 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) | 54 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail }) |
43 | } | 55 | } |
44 | 56 | ||
45 | function generateVideoMiniature (video: VideoModel, videoFile: VideoFileModel, type: ThumbnailType) { | 57 | function generateVideoMiniature (video: VideoModel, videoFile: VideoFileModel, type: ThumbnailType) { |
@@ -50,7 +62,7 @@ function generateVideoMiniature (video: VideoModel, videoFile: VideoFileModel, t | |||
50 | ? () => processImage(ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, outputPath, { width, height }, true) | 62 | ? () => processImage(ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, outputPath, { width, height }, true) |
51 | : () => generateImageFromVideoFile(input, basePath, filename, { height, width }) | 63 | : () => generateImageFromVideoFile(input, basePath, filename, { height, width }) |
52 | 64 | ||
53 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail }) | 65 | return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated: true, existingThumbnail }) |
54 | } | 66 | } |
55 | 67 | ||
56 | function createPlaceholderThumbnail (fileUrl: string, video: VideoModel, type: ThumbnailType, size: ImageSize) { | 68 | function createPlaceholderThumbnail (fileUrl: string, video: VideoModel, type: ThumbnailType, size: ImageSize) { |
@@ -134,10 +146,11 @@ async function createThumbnailFromFunction (parameters: { | |||
134 | height: number, | 146 | height: number, |
135 | width: number, | 147 | width: number, |
136 | type: ThumbnailType, | 148 | type: ThumbnailType, |
149 | automaticallyGenerated?: boolean, | ||
137 | fileUrl?: string, | 150 | fileUrl?: string, |
138 | existingThumbnail?: ThumbnailModel | 151 | existingThumbnail?: ThumbnailModel |
139 | }) { | 152 | }) { |
140 | const { thumbnailCreator, filename, width, height, type, existingThumbnail, fileUrl = null } = parameters | 153 | const { thumbnailCreator, filename, width, height, type, existingThumbnail, automaticallyGenerated = null, fileUrl = null } = parameters |
141 | 154 | ||
142 | const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel() | 155 | const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel() |
143 | 156 | ||
@@ -146,6 +159,7 @@ async function createThumbnailFromFunction (parameters: { | |||
146 | thumbnail.width = width | 159 | thumbnail.width = width |
147 | thumbnail.type = type | 160 | thumbnail.type = type |
148 | thumbnail.fileUrl = fileUrl | 161 | thumbnail.fileUrl = fileUrl |
162 | thumbnail.automaticallyGenerated = automaticallyGenerated | ||
149 | 163 | ||
150 | await thumbnailCreator() | 164 | await thumbnailCreator() |
151 | 165 | ||