]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/remote.js
Server: fix logs when adding a remote video
[github/Chocobozzz/PeerTube.git] / server / controllers / api / remote.js
index 94808693d4558e1be922fe66790597b9a2cbad82..2d0db51c02e47435a10f8bdbacf718c10bfd26b8 100644 (file)
@@ -30,7 +30,7 @@ module.exports = router
 
 function remoteVideos (req, res, next) {
   const requests = req.body.data
-  const fromUrl = req.body.signature.url
+  const fromHost = req.body.signature.host
 
   // We need to process in the same order to keep consistency
   // TODO: optimization
@@ -40,7 +40,7 @@ function remoteVideos (req, res, next) {
     if (request.type === 'add') {
       addRemoteVideo(videoData, callbackEach)
     } else if (request.type === 'remove') {
-      removeRemoteVideo(videoData, fromUrl, callbackEach)
+      removeRemoteVideo(videoData, fromHost, callbackEach)
     } else {
       logger.error('Unkown remote request type %s.', request.type)
     }
@@ -53,25 +53,29 @@ function remoteVideos (req, res, next) {
 }
 
 function addRemoteVideo (videoToCreateData, callback) {
-  logger.debug('Adding remote video %s.', videoToCreateData.magnetUri)
-
-  // Mongoose pre hook will automatically create the thumbnail on disk
-  videoToCreateData.thumbnail = videoToCreateData.thumbnailBase64
+  logger.debug('Adding remote video "%s".', videoToCreateData.name)
 
   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, fromUrl, callback) {
+function removeRemoteVideo (videoToRemoveData, fromHost, callback) {
   // We need the list because we have to remove some other stuffs (thumbnail etc)
-  Video.listByUrlAndRemoteId(fromUrl, videoToRemoveData.remoteId, function (err, videosList) {
+  Video.listByHostAndRemoteId(fromHost, videoToRemoveData.remoteId, function (err, videosList) {
     if (err) {
-      logger.error('Cannot list videos from url and magnets.', { error: err })
+      logger.error('Cannot list videos from host and magnets.', { error: err })
       return callback(err)
     }
 
     if (videosList.length === 0) {
-      logger.error('No remote video was found for this pod.', { magnetUri: videoToRemoveData.magnetUri, podUrl: fromUrl })
+      logger.error('No remote video was found for this pod.', { magnetUri: videoToRemoveData.magnetUri, podHost: fromHost })
     }
 
     each(videosList, function (video, callbackEach) {