mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Support lazy download thumbnails
This commit is contained in:
parent
a673d9e848
commit
f162d32da0
27 changed files with 272 additions and 212 deletions
|
@ -7,13 +7,12 @@ 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'
|
||||
import { downloadImageFromWorker, processImageFromWorker } from './worker/parent-process'
|
||||
|
||||
type ImageSize = { height?: number, width?: number }
|
||||
|
||||
function updatePlaylistMiniatureFromExisting (options: {
|
||||
function updateLocalPlaylistMiniatureFromExisting (options: {
|
||||
inputPath: string
|
||||
playlist: MVideoPlaylistThumbnail
|
||||
automaticallyGenerated: boolean
|
||||
|
@ -35,6 +34,7 @@ function updatePlaylistMiniatureFromExisting (options: {
|
|||
width,
|
||||
type,
|
||||
automaticallyGenerated,
|
||||
onDisk: true,
|
||||
existingThumbnail
|
||||
})
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ function updatePlaylistMiniatureFromUrl (options: {
|
|||
return downloadImageFromWorker({ url: downloadUrl, destDir: basePath, destName: filename, size: { width, height } })
|
||||
}
|
||||
|
||||
return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
|
||||
return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl, onDisk: true })
|
||||
}
|
||||
|
||||
function updateVideoMiniatureFromUrl (options: {
|
||||
|
@ -89,10 +89,10 @@ function updateVideoMiniatureFromUrl (options: {
|
|||
return Promise.resolve()
|
||||
}
|
||||
|
||||
return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
|
||||
return updateThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl, onDisk: true })
|
||||
}
|
||||
|
||||
function updateVideoMiniatureFromExisting (options: {
|
||||
function updateLocalVideoMiniatureFromExisting (options: {
|
||||
inputPath: string
|
||||
video: MVideoThumbnail
|
||||
type: ThumbnailType
|
||||
|
@ -115,11 +115,12 @@ function updateVideoMiniatureFromExisting (options: {
|
|||
width,
|
||||
type,
|
||||
automaticallyGenerated,
|
||||
existingThumbnail
|
||||
existingThumbnail,
|
||||
onDisk: true
|
||||
})
|
||||
}
|
||||
|
||||
function generateVideoMiniature (options: {
|
||||
function generateLocalVideoMiniature (options: {
|
||||
video: MVideoThumbnail
|
||||
videoFile: MVideoFile
|
||||
type: ThumbnailType
|
||||
|
@ -150,34 +151,36 @@ function generateVideoMiniature (options: {
|
|||
width,
|
||||
type,
|
||||
automaticallyGenerated: true,
|
||||
onDisk: true,
|
||||
existingThumbnail
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function updatePlaceholderThumbnail (options: {
|
||||
function updateRemoteThumbnail (options: {
|
||||
fileUrl: string
|
||||
video: MVideoThumbnail
|
||||
type: ThumbnailType
|
||||
size: ImageSize
|
||||
onDisk: boolean
|
||||
}) {
|
||||
const { fileUrl, video, type, size } = options
|
||||
const { filename: updatedFilename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
|
||||
const { fileUrl, video, type, size, onDisk } = options
|
||||
const { filename: generatedFilename, height, width, existingThumbnail } = buildMetadataFromVideo(video, type, size)
|
||||
|
||||
const thumbnailUrlChanged = hasThumbnailUrlChanged(existingThumbnail, fileUrl, video)
|
||||
|
||||
const thumbnail = existingThumbnail || new ThumbnailModel()
|
||||
|
||||
// Do not change the thumbnail filename if the file did not change
|
||||
const filename = thumbnailUrlChanged
|
||||
? updatedFilename
|
||||
: existingThumbnail.filename
|
||||
if (thumbnailUrlChanged) {
|
||||
thumbnail.filename = generatedFilename
|
||||
}
|
||||
|
||||
thumbnail.filename = filename
|
||||
thumbnail.height = height
|
||||
thumbnail.width = width
|
||||
thumbnail.type = type
|
||||
thumbnail.fileUrl = fileUrl
|
||||
thumbnail.onDisk = onDisk
|
||||
|
||||
return thumbnail
|
||||
}
|
||||
|
@ -185,14 +188,18 @@ function updatePlaceholderThumbnail (options: {
|
|||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
generateVideoMiniature,
|
||||
generateLocalVideoMiniature,
|
||||
updateVideoMiniatureFromUrl,
|
||||
updateVideoMiniatureFromExisting,
|
||||
updatePlaceholderThumbnail,
|
||||
updateLocalVideoMiniatureFromExisting,
|
||||
updateRemoteThumbnail,
|
||||
updatePlaylistMiniatureFromUrl,
|
||||
updatePlaylistMiniatureFromExisting
|
||||
updateLocalPlaylistMiniatureFromExisting
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Private
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function hasThumbnailUrlChanged (existingThumbnail: MThumbnail, downloadUrl: string, video: MVideoUUID) {
|
||||
const existingUrl = existingThumbnail
|
||||
? existingThumbnail.fileUrl
|
||||
|
@ -258,6 +265,7 @@ async function updateThumbnailFromFunction (parameters: {
|
|||
height: number
|
||||
width: number
|
||||
type: ThumbnailType
|
||||
onDisk: boolean
|
||||
automaticallyGenerated?: boolean
|
||||
fileUrl?: string
|
||||
existingThumbnail?: MThumbnail
|
||||
|
@ -269,6 +277,7 @@ async function updateThumbnailFromFunction (parameters: {
|
|||
height,
|
||||
type,
|
||||
existingThumbnail,
|
||||
onDisk,
|
||||
automaticallyGenerated = null,
|
||||
fileUrl = null
|
||||
} = parameters
|
||||
|
@ -285,6 +294,7 @@ async function updateThumbnailFromFunction (parameters: {
|
|||
thumbnail.type = type
|
||||
thumbnail.fileUrl = fileUrl
|
||||
thumbnail.automaticallyGenerated = automaticallyGenerated
|
||||
thumbnail.onDisk = onDisk
|
||||
|
||||
if (oldFilename) thumbnail.previousThumbnailFilename = oldFilename
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue