diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-11-16 21:16:41 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-11-16 21:16:41 +0100 |
commit | c77fa067a18a1fea34d5f277da19c2e4712018fa (patch) | |
tree | d68419f2449f5ec8db70e312b788e6c56d49c11c /server/models/video.js | |
parent | 9c24c07051196696fa41c3e642150ba362991055 (diff) | |
download | PeerTube-c77fa067a18a1fea34d5f277da19c2e4712018fa.tar.gz PeerTube-c77fa067a18a1fea34d5f277da19c2e4712018fa.tar.zst PeerTube-c77fa067a18a1fea34d5f277da19c2e4712018fa.zip |
Server: fix thumbnail in remote videos
Diffstat (limited to 'server/models/video.js')
-rw-r--r-- | server/models/video.js | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/server/models/video.js b/server/models/video.js index d7d99acd6..527652230 100644 --- a/server/models/video.js +++ b/server/models/video.js | |||
@@ -57,6 +57,7 @@ VideoSchema.methods = { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | VideoSchema.statics = { | 59 | VideoSchema.statics = { |
60 | generateThumbnailFromBase64, | ||
60 | getDurationFromFile, | 61 | getDurationFromFile, |
61 | listForApi, | 62 | listForApi, |
62 | listByHostAndRemoteId, | 63 | listByHostAndRemoteId, |
@@ -136,10 +137,10 @@ VideoSchema.pre('save', function (next) { | |||
136 | } | 137 | } |
137 | ) | 138 | ) |
138 | 139 | ||
139 | parallel(tasks, next) | 140 | return parallel(tasks, next) |
140 | } else { | ||
141 | generateThumbnailFromBase64(video, video.thumbnail, next) | ||
142 | } | 141 | } |
142 | |||
143 | return next() | ||
143 | }) | 144 | }) |
144 | 145 | ||
145 | mongoose.model('Video', VideoSchema) | 146 | mongoose.model('Video', VideoSchema) |
@@ -251,6 +252,18 @@ function toRemoteJSON (callback) { | |||
251 | 252 | ||
252 | // ------------------------------ STATICS ------------------------------ | 253 | // ------------------------------ STATICS ------------------------------ |
253 | 254 | ||
255 | function generateThumbnailFromBase64 (video, thumbnailData, callback) { | ||
256 | // Creating the thumbnail for a remote video | ||
257 | |||
258 | const thumbnailName = video.getThumbnailName() | ||
259 | const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName | ||
260 | fs.writeFile(thumbnailPath, thumbnailData, { encoding: 'base64' }, function (err) { | ||
261 | if (err) return callback(err) | ||
262 | |||
263 | return callback(null, thumbnailName) | ||
264 | }) | ||
265 | } | ||
266 | |||
254 | function getDurationFromFile (videoPath, callback) { | 267 | function getDurationFromFile (videoPath, callback) { |
255 | ffmpeg.ffprobe(videoPath, function (err, metadata) { | 268 | ffmpeg.ffprobe(videoPath, function (err, metadata) { |
256 | if (err) return callback(err) | 269 | if (err) return callback(err) |
@@ -333,18 +346,6 @@ function createThumbnail (video, videoPath, callback) { | |||
333 | generateImage(video, videoPath, constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), constants.THUMBNAILS_SIZE, callback) | 346 | generateImage(video, videoPath, constants.CONFIG.STORAGE.THUMBNAILS_DIR, video.getThumbnailName(), constants.THUMBNAILS_SIZE, callback) |
334 | } | 347 | } |
335 | 348 | ||
336 | function generateThumbnailFromBase64 (video, thumbnailData, callback) { | ||
337 | // Creating the thumbnail for this remote video) | ||
338 | |||
339 | const thumbnailName = video.getThumbnailName() | ||
340 | const thumbnailPath = constants.CONFIG.STORAGE.THUMBNAILS_DIR + thumbnailName | ||
341 | fs.writeFile(thumbnailPath, thumbnailData, { encoding: 'base64' }, function (err) { | ||
342 | if (err) return callback(err) | ||
343 | |||
344 | return callback(null, thumbnailName) | ||
345 | }) | ||
346 | } | ||
347 | |||
348 | function generateImage (video, videoPath, folder, imageName, size, callback) { | 349 | function generateImage (video, videoPath, folder, imageName, size, callback) { |
349 | const options = { | 350 | const options = { |
350 | filename: imageName, | 351 | filename: imageName, |