]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/thumbnail.ts
Fix video views
[github/Chocobozzz/PeerTube.git] / server / lib / thumbnail.ts
index 344c28566798ed48a080a72f675871311fab4a82..950b14c3bd18187a019f8213bcfbfff2f715c6f4 100644 (file)
@@ -12,37 +12,37 @@ import { VideoPlaylistModel } from '../models/video/video-playlist'
 
 type ImageSize = { height: number, width: number }
 
-function createPlaylistThumbnailFromExisting (inputPath: string, playlist: VideoPlaylistModel, keepOriginal = false, size?: ImageSize) {
+function createPlaylistMiniatureFromExisting (inputPath: string, playlist: VideoPlaylistModel, keepOriginal = false, size?: ImageSize) {
   const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size)
-  const type = ThumbnailType.THUMBNAIL
+  const type = ThumbnailType.MINIATURE
 
-  const thumbnailCreator = () => processImage({ path: inputPath }, outputPath, { width, height }, keepOriginal)
+  const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height }, keepOriginal)
   return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail })
 }
 
-function createPlaylistThumbnailFromUrl (url: string, playlist: VideoPlaylistModel, size?: ImageSize) {
+function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: VideoPlaylistModel, size?: ImageSize) {
   const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size)
-  const type = ThumbnailType.THUMBNAIL
+  const type = ThumbnailType.MINIATURE
 
-  const thumbnailCreator = () => downloadImage(url, basePath, filename, { width, height })
-  return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, url })
+  const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height })
+  return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
 }
 
-function createVideoThumbnailFromUrl (url: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) {
+function createVideoMiniatureFromUrl (fileUrl: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) {
   const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
-  const thumbnailCreator = () => downloadImage(url, basePath, filename, { width, height })
+  const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height })
 
-  return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, url })
+  return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
 }
 
-function createVideoThumbnailFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) {
+function createVideoMiniatureFromExisting (inputPath: string, video: VideoModel, type: ThumbnailType, size?: ImageSize) {
   const { filename, outputPath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
-  const thumbnailCreator = () => processImage({ path: inputPath }, outputPath, { width, height })
+  const thumbnailCreator = () => processImage(inputPath, outputPath, { width, height })
 
   return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail })
 }
 
-function generateVideoThumbnail (video: VideoModel, videoFile: VideoFileModel, type: ThumbnailType) {
+function generateVideoMiniature (video: VideoModel, videoFile: VideoFileModel, type: ThumbnailType) {
   const input = video.getVideoFilePath(videoFile)
 
   const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type)
@@ -51,7 +51,7 @@ function generateVideoThumbnail (video: VideoModel, videoFile: VideoFileModel, t
   return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail })
 }
 
-function createPlaceholderThumbnail (url: string, video: VideoModel, type: ThumbnailType, size: ImageSize) {
+function createPlaceholderThumbnail (fileUrl: string, video: VideoModel, type: ThumbnailType, size: ImageSize) {
   const { filename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
 
   const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel()
@@ -60,7 +60,7 @@ function createPlaceholderThumbnail (url: string, video: VideoModel, type: Thumb
   thumbnail.height = height
   thumbnail.width = width
   thumbnail.type = type
-  thumbnail.url = url
+  thumbnail.fileUrl = fileUrl
 
   return thumbnail
 }
@@ -68,12 +68,12 @@ function createPlaceholderThumbnail (url: string, video: VideoModel, type: Thumb
 // ---------------------------------------------------------------------------
 
 export {
-  generateVideoThumbnail,
-  createVideoThumbnailFromUrl,
-  createVideoThumbnailFromExisting,
+  generateVideoMiniature,
+  createVideoMiniatureFromUrl,
+  createVideoMiniatureFromExisting,
   createPlaceholderThumbnail,
-  createPlaylistThumbnailFromUrl,
-  createPlaylistThumbnailFromExisting
+  createPlaylistMiniatureFromUrl,
+  createPlaylistMiniatureFromExisting
 }
 
 function buildMetadataFromPlaylist (playlist: VideoPlaylistModel, size: ImageSize) {
@@ -95,7 +95,7 @@ function buildMetadataFromVideo (video: VideoModel, type: ThumbnailType, size?:
     ? video.Thumbnails.find(t => t.type === type)
     : undefined
 
-  if (type === ThumbnailType.THUMBNAIL) {
+  if (type === ThumbnailType.MINIATURE) {
     const filename = video.generateThumbnailName()
     const basePath = CONFIG.STORAGE.THUMBNAILS_DIR
 
@@ -132,10 +132,10 @@ async function createThumbnailFromFunction (parameters: {
   height: number,
   width: number,
   type: ThumbnailType,
-  url?: string,
+  fileUrl?: string,
   existingThumbnail?: ThumbnailModel
 }) {
-  const { thumbnailCreator, filename, width, height, type, existingThumbnail, url = null } = parameters
+  const { thumbnailCreator, filename, width, height, type, existingThumbnail, fileUrl = null } = parameters
 
   const thumbnail = existingThumbnail ? existingThumbnail : new ThumbnailModel()
 
@@ -143,7 +143,7 @@ async function createThumbnailFromFunction (parameters: {
   thumbnail.height = height
   thumbnail.width = width
   thumbnail.type = type
-  thumbnail.url = url
+  thumbnail.fileUrl = fileUrl
 
   await thumbnailCreator()