]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/thumbnail.ts
Force live stream termination
[github/Chocobozzz/PeerTube.git] / server / lib / thumbnail.ts
index aa2d7a8132923a77e0b0a1eaa9f34c0d861e0c3e..02b867a91e6b9fd833514aa82093595925520aba 100644 (file)
@@ -1,14 +1,15 @@
 import { join } from 'path'
 import { ThumbnailType } from '@shared/models'
-import { generateImageFilename, generateImageFromVideoFile, processImage } from '../helpers/image-utils'
-import { downloadImage } from '../helpers/requests'
+import { generateImageFilename, generateImageFromVideoFile } from '../helpers/image-utils'
 import { CONFIG } from '../initializers/config'
 import { ASSETS_PATH, PREVIEWS_SIZE, THUMBNAILS_SIZE } from '../initializers/constants'
 import { ThumbnailModel } from '../models/video/thumbnail'
 import { MVideoFile, MVideoThumbnail, MVideoUUID } from '../types/models'
 import { MThumbnail } from '../types/models/video/thumbnail'
 import { MVideoPlaylistThumbnail } from '../types/models/video/video-playlist'
+import { downloadImageFromWorker } from './local-actor'
 import { VideoPathManager } from './video-path-manager'
+import { processImageFromWorker } from './worker/parent-process'
 
 type ImageSize = { height?: number, width?: number }
 
@@ -23,7 +24,10 @@ function updatePlaylistMiniatureFromExisting (options: {
   const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size)
   const type = ThumbnailType.MINIATURE
 
-  const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal)
+  const thumbnailCreator = () => {
+    return processImageFromWorker({ path: inputPath, destination: outputPath, newSize: { width, height }, keepOriginal })
+  }
+
   return updateThumbnailFromFunction({
     thumbnailCreator,
     filename,
@@ -49,7 +53,10 @@ function updatePlaylistMiniatureFromUrl (options: {
     ? null
     : downloadUrl
 
-  const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height })
+  const thumbnailCreator = () => {
+    return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } })
+  }
+
   return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
 }
 
@@ -75,7 +82,9 @@ function updateVideoMiniatureFromUrl (options: {
     : existingThumbnail.filename
 
   const thumbnailCreator = () => {
-    if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height })
+    if (thumbnailUrlChanged) {
+      return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } })
+    }
 
     return Promise.resolve()
   }
@@ -94,7 +103,10 @@ function updateVideoMiniatureFromExisting (options: {
   const { inputPath, video, type, automaticallyGenerated, size, keepOriginal = false } = options
 
   const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
-  const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal)
+
+  const thumbnailCreator = () => {
+    return processImageFromWorker({ path: inputPath, destination: outputPath, newSize: { width, height }, keepOriginal })
+  }
 
   return updateThumbnailFromFunction({
     thumbnailCreator,
@@ -118,8 +130,18 @@ function generateVideoMiniature (options: {
     const { filename, basePath, height, width, existingThumbnail, outputPath } = buildMetadataFromVideo(video, type)
 
     const thumbnailCreator = videoFile.isAudio()
-      ? () => processImage(ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND, outputPath, { width, height }, true)
-      : () => generateImageFromVideoFile(input, basePath, filename, { height, width })
+      ? () => processImageFromWorker({
+        path: ASSETS_PATH.DEFAULT_AUDIO_BACKGROUND,
+        destination: outputPath,
+        newSize: { width, height },
+        keepOriginal: true
+      })
+      : () => generateImageFromVideoFile({
+        fromPath: input,
+        folder: basePath,
+        imageName: filename,
+        size: { height, width }
+      })
 
     return updateThumbnailFromFunction({
       thumbnailCreator,