mirror of https://github.com/Chocobozzz/PeerTube
Server: fix thumbnail in remote videos
parent
9c24c07051
commit
c77fa067a1
|
@ -55,11 +55,15 @@ function remoteVideos (req, res, next) {
|
||||||
function addRemoteVideo (videoToCreateData, callback) {
|
function addRemoteVideo (videoToCreateData, callback) {
|
||||||
logger.debug('Adding remote video %s.', videoToCreateData.magnetUri)
|
logger.debug('Adding remote video %s.', videoToCreateData.magnetUri)
|
||||||
|
|
||||||
// Mongoose pre hook will automatically create the thumbnail on disk
|
|
||||||
videoToCreateData.thumbnail = videoToCreateData.thumbnailBase64
|
|
||||||
|
|
||||||
const video = new Video(videoToCreateData)
|
const video = new Video(videoToCreateData)
|
||||||
video.save(callback)
|
Video.generateThumbnailFromBase64(video, videoToCreateData.thumbnailBase64, function (err) {
|
||||||
|
if (err) {
|
||||||
|
logger.error('Cannot generate thumbnail from base 64 data.', { error: err })
|
||||||
|
return callback(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
video.save(callback)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeRemoteVideo (videoToRemoveData, fromHost, callback) {
|
function removeRemoteVideo (videoToRemoveData, fromHost, callback) {
|
||||||
|
|
|
@ -57,6 +57,7 @@ VideoSchema.methods = {
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoSchema.statics = {
|
VideoSchema.statics = {
|
||||||
|
generateThumbnailFromBase64,
|
||||||
getDurationFromFile,
|
getDurationFromFile,
|
||||||
listForApi,
|
listForApi,
|
||||||
listByHostAndRemoteId,
|
listByHostAndRemoteId,
|
||||||
|
@ -136,10 +137,10 @@ VideoSchema.pre('save', function (next) {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
parallel(tasks, next)
|
return parallel(tasks, next)
|
||||||
} else {
|
|
||||||
generateThumbnailFromBase64(video, video.thumbnail, next)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return next()
|
||||||
})
|
})
|
||||||
|
|
||||||
mongoose.model('Video', VideoSchema)
|
mongoose.model('Video', VideoSchema)
|
||||||
|
@ -251,6 +252,18 @@ function toRemoteJSON (callback) {
|
||||||
|
|
||||||
// ------------------------------ STATICS ------------------------------
|
// ------------------------------ STATICS ------------------------------
|
||||||
|
|
||||||
|
function generateThumbnailFromBase64 (video, thumbnailData, callback) {
|
||||||
|
// Creating the thumbnail for a remote video
|
||||||
|
|
||||||
|
const thumbnailName = video.getThumbnailName()
|
||||||
|
const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName
|
||||||
|
fs.writeFile(thumbnailPath, thumbnailData, { encoding: 'base64' }, function (err) {
|
||||||
|
if (err) return callback(err)
|
||||||
|
|
||||||
|
return callback(null, thumbnailName)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function getDurationFromFile (videoPath, callback) {
|
function getDurationFromFile (videoPath, callback) {
|
||||||
ffmpeg.ffprobe(videoPath, function (err, metadata) {
|
ffmpeg.ffprobe(videoPath, function (err, metadata) {
|
||||||
if (err) return callback(err)
|
if (err) return callback(err)
|
||||||
|
@ -333,18 +346,6 @@ function createThumbnail (video, videoPath, callback) {
|
||||||
generateImage(video, videoPath, constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), constants.THUMBNAILS_SIZE, callback)
|
generateImage(video, videoPath, constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), constants.THUMBNAILS_SIZE, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateThumbnailFromBase64 (video, thumbnailData, callback) {
|
|
||||||
// Creating the thumbnail for this remote video)
|
|
||||||
|
|
||||||
const thumbnailName = video.getThumbnailName()
|
|
||||||
const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName
|
|
||||||
fs.writeFile(thumbnailPath, thumbnailData, { encoding: 'base64' }, function (err) {
|
|
||||||
if (err) return callback(err)
|
|
||||||
|
|
||||||
return callback(null, thumbnailName)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateImage (video, videoPath, folder, imageName, size, callback) {
|
function generateImage (video, videoPath, folder, imageName, size, callback) {
|
||||||
const options = {
|
const options = {
|
||||||
filename: imageName,
|
filename: imageName,
|
||||||
|
|
Loading…
Reference in New Issue