X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fthumbnail.ts;h=740b83acb15414748f2068a3b905a737f90cd6fc;hb=a8b1b40485145ac1eae513a661d7dd6e0986ce96;hp=84791955e0cc00c908b9882dae22377b93dd9188;hpb=453e83ea5d81d203ba34bc43cd5c2c750ba40568;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/thumbnail.ts b/server/lib/thumbnail.ts index 84791955e..740b83acb 100644 --- a/server/lib/thumbnail.ts +++ b/server/lib/thumbnail.ts @@ -6,9 +6,10 @@ 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 } @@ -26,36 +27,49 @@ function createPlaylistMiniatureFromExisting ( return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, automaticallyGenerated, existingThumbnail }) } -function createPlaylistMiniatureFromUrl (fileUrl: string, playlist: MVideoPlaylistThumbnail, size?: ImageSize) { +function createPlaylistMiniatureFromUrl (downloadUrl: string, playlist: MVideoPlaylistThumbnail, size?: ImageSize) { const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromPlaylist(playlist, size) const type = ThumbnailType.MINIATURE - const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height }) + // Only save the file URL if it is a remote playlist + const fileUrl = playlist.isOwned() + ? null + : downloadUrl + + const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height }) return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl }) } -function createVideoMiniatureFromUrl (fileUrl: string, video: MVideoThumbnail, type: ThumbnailType, size?: ImageSize) { +function createVideoMiniatureFromUrl (downloadUrl: string, video: MVideoThumbnail, type: ThumbnailType, size?: ImageSize) { const { filename, basePath, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size) - const thumbnailCreator = () => downloadImage(fileUrl, basePath, filename, { width, height }) + // Only save the file URL if it is a remote video + const fileUrl = video.isOwned() + ? null + : downloadUrl + + const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height }) 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 }) } function generateVideoMiniature (video: MVideoThumbnail, videoFile: MVideoFile, type: ThumbnailType) { - const input = video.getVideoFilePath(videoFile) + const input = getVideoFilePath(video, videoFile) const { filename, basePath, height, width, existingThumbnail, outputPath } = buildMetadataFromVideo(video, type) const thumbnailCreator = videoFile.isAudio() @@ -68,7 +82,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 @@ -141,18 +155,18 @@ function buildMetadataFromVideo (video: MVideoThumbnail, type: ThumbnailType, si } async function createThumbnailFromFunction (parameters: { - thumbnailCreator: () => Promise, - filename: string, - height: number, - width: number, - type: ThumbnailType, - automaticallyGenerated?: boolean, - fileUrl?: string, + thumbnailCreator: () => Promise + 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