]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video.js
Server: set manually the post host of a remote video throught the
[github/Chocobozzz/PeerTube.git] / server / models / video.js
index 6d3fa3fb83be13618a91271e8a7513b0ac98bbb9..330067cdfa6e892776692f1787fd70efe22f2ea4 100644 (file)
@@ -57,6 +57,7 @@ VideoSchema.methods = {
 }
 
 VideoSchema.statics = {
+  generateThumbnailFromBase64,
   getDurationFromFile,
   listForApi,
   listByHostAndRemoteId,
@@ -124,7 +125,6 @@ VideoSchema.pre('save', function (next) {
             const parsedTorrent = parseTorrent(torrent)
             video.magnet.infoHash = parsedTorrent.infoHash
 
-            console.log(parsedTorrent)
             callback(null)
           })
         })
@@ -137,10 +137,10 @@ VideoSchema.pre('save', function (next) {
       }
     )
 
-    parallel(tasks, next)
-  } else {
-    generateThumbnailFromBase64(video, video.thumbnail, next)
+    return parallel(tasks, next)
   }
+
+  return next()
 })
 
 mongoose.model('Video', VideoSchema)
@@ -155,7 +155,7 @@ function generateMagnetUri () {
     baseUrlWs = constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT
   } else {
     baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.podHost
-    baseUrlWs = constants.REMOTE_SCHEME.WS + this.podHost
+    baseUrlWs = constants.REMOTE_SCHEME.WS + '://' + this.podHost
   }
 
   const xs = baseUrlHttp + constants.STATIC_PATHS.TORRENTS + this.getTorrentName()
@@ -243,7 +243,7 @@ function toRemoteJSON (callback) {
       thumbnailBase64: new Buffer(thumbnailData).toString('base64'),
       tags: self.tags,
       createdDate: self.createdDate,
-      podHost: self.podHost
+      extname: self.extname
     }
 
     return callback(null, remoteVideo)
@@ -252,6 +252,18 @@ function toRemoteJSON (callback) {
 
 // ------------------------------ 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) {
   ffmpeg.ffprobe(videoPath, function (err, metadata) {
     if (err) return callback(err)
@@ -334,18 +346,6 @@ function createThumbnail (video, videoPath, 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) {
   const options = {
     filename: imageName,