]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/thumbnail.ts
Process remaining segment hashes on live ending
[github/Chocobozzz/PeerTube.git] / server / lib / thumbnail.ts
index a99f716290accecf0dc89fd038966cdd8323a7c9..dc86423f832d3e12474a0ef79afd4986852d8a57 100644 (file)
@@ -6,9 +6,9 @@ import { ThumbnailType } from '../../shared/models/videos/thumbnail.type'
 import { processImage } from '../helpers/image-utils'
 import { join } from 'path'
 import { downloadImage } from '../helpers/requests'
-import { MVideoPlaylistThumbnail } from '../typings/models/video/video-playlist'
-import { MVideoFile, MVideoThumbnail } from '../typings/models'
-import { MThumbnail } from '../typings/models/video/thumbnail'
+import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist'
+import { MVideoFile, MVideoThumbnail } from '../types/models'
+import { MThumbnail } from '../types/models/video/thumbnail'
 import { getVideoFilePath } from './video-paths'
 
 type ImageSize = { height: number, width: number }
@@ -42,15 +42,18 @@ function createVideoMiniatureFromUrl (fileUrl: string, video: MVideoThumbnail, t
   return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
 }
 
-function createVideoMiniatureFromExisting (
-  inputPath: string,
-  video: MVideoThumbnail,
-  type: ThumbnailType,
-  automaticallyGenerated: boolean,
+function createVideoMiniatureFromExisting (options: {
+  inputPath: string
+  video: MVideoThumbnail
+  type: ThumbnailType
+  automaticallyGenerated: boolean
   size?: ImageSize
-) {
+  keepOriginal?: boolean
+}) {
+  const { inputPath, video, type, automaticallyGenerated, size, keepOriginal } = options
+
   const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
-  const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height })
+  const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal)
 
   return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail })
 }
@@ -69,7 +72,7 @@ function generateVideoMiniature (video: MVideoThumbnail, videoFile: MVideoFile,
 function createPlaceholderThumbnail (fileUrl: string, video: MVideoThumbnail, type: ThumbnailType, size: ImageSize) {
   const { filename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
 
-  const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel()
+  const thumbnail = existingThumbnail || new ThumbnailModel()
 
   thumbnail.filename = filename
   thumbnail.height = height
@@ -142,18 +145,18 @@ function buildMetadataFromVideo (video: MVideoThumbnail, type: ThumbnailType, si
 }
 
 async function createThumbnailFromFunction (parameters: {
-  thumbnailCreator: () => Promise<any>,
-  filename: string,
-  height: number,
-  width: number,
-  type: ThumbnailType,
-  automaticallyGenerated?: boolean,
-  fileUrl?: string,
+  thumbnailCreator: () => Promise<any>
+  filename: string
+  height: number
+  width: number
+  type: ThumbnailType
+  automaticallyGenerated?: boolean
+  fileUrl?: string
   existingThumbnail?: MThumbnail
 }) {
   const { thumbnailCreator, filename, width, height, type, existingThumbnail, automaticallyGenerated = null, fileUrl = null } = parameters
 
-  const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel()
+  const thumbnail = existingThumbnail || new ThumbnailModel()
 
   thumbnail.filename = filename
   thumbnail.height = height