Optimize remote thumbnail processing
This commit is contained in:
parent
a35a22797c
commit
374b725df5
2 changed files with 23 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
|
import chaiJsonSchema = require('chai-json-schema')
|
||||||
|
import { copy, move } from 'fs-extra'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
|
|
||||||
import { ThumbnailType } from '../../shared/models/videos/thumbnail.type'
|
import { ThumbnailType } from '../../shared/models/videos/thumbnail.type'
|
||||||
import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils'
|
import { generateImageFromVideoFile } from '../helpers/ffmpeg-utils'
|
||||||
import { processImage } from '../helpers/image-utils'
|
import { processImage } from '../helpers/image-utils'
|
||||||
|
@ -69,7 +70,19 @@ function createVideoMiniatureFromUrl (options: {
|
||||||
? null
|
? null
|
||||||
: downloadUrl
|
: downloadUrl
|
||||||
|
|
||||||
const thumbnailCreator = () => downloadImage(downloadUrl, basePath, filename, { width, height })
|
// If the thumbnail URL did not change
|
||||||
|
const existingUrl = existingThumbnail
|
||||||
|
? existingThumbnail.fileUrl
|
||||||
|
: null
|
||||||
|
|
||||||
|
// If the thumbnail URL did not change and has a unique filename (introduced in 3.2), avoid thumbnail processing
|
||||||
|
const thumbnailUrlChanged = !existingUrl || existingUrl !== downloadUrl || downloadUrl.endsWith(`${video.uuid}.jpg`)
|
||||||
|
const thumbnailCreator = () => {
|
||||||
|
if (thumbnailUrlChanged) return downloadImage(downloadUrl, basePath, filename, { width, height })
|
||||||
|
|
||||||
|
return copy(existingThumbnail.getPath(), ThumbnailModel.buildPath(type, filename))
|
||||||
|
}
|
||||||
|
|
||||||
return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
|
return createThumbnailFromFunction({ thumbnailCreator, filename, height, width, type, existingThumbnail, fileUrl })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,6 +158,12 @@ export class ThumbnailModel extends Model {
|
||||||
return ThumbnailModel.findOne(query)
|
return ThumbnailModel.findOne(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static buildPath (type: ThumbnailType, filename: string) {
|
||||||
|
const directory = ThumbnailModel.types[type].directory
|
||||||
|
|
||||||
|
return join(directory, filename)
|
||||||
|
}
|
||||||
|
|
||||||
getFileUrl (video: MVideoAccountLight) {
|
getFileUrl (video: MVideoAccountLight) {
|
||||||
const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename
|
const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename
|
||||||
|
|
||||||
|
@ -169,13 +175,11 @@ export class ThumbnailModel extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
getPath () {
|
getPath () {
|
||||||
const directory = ThumbnailModel.types[this.type].directory
|
return ThumbnailModel.buildPath(this.type, this.filename)
|
||||||
return join(directory, this.filename)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPreviousPath () {
|
getPreviousPath () {
|
||||||
const directory = ThumbnailModel.types[this.type].directory
|
return ThumbnailModel.buildPath(this.type, this.previousThumbnailFilename)
|
||||||
return join(directory, this.previousThumbnailFilename)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeThumbnail () {
|
removeThumbnail () {
|
||||||
|
|
Loading…
Reference in a new issue