]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/v1/videos.js
Move video duration logic in lib/
[github/Chocobozzz/PeerTube.git] / server / controllers / api / v1 / videos.js
index d25ca95f72c7b2c37646279df85b5c66f7057a7d..7fdc50e5239d742ecd33d086237bc54afc8c018e 100644 (file)
@@ -60,26 +60,35 @@ function addVideo (req, res, next) {
       return next(err)
     }
 
-    const video_data = {
-      name: video_infos.name,
-      namePath: video_file.filename,
-      description: video_infos.description,
-      magnetUri: torrent.magnetURI,
-      author: res.locals.oauth.token.user.username
-    }
-
-    Videos.add(video_data, function (err) {
+    videos.getVideoDuration(video_file.path, function (err, duration) {
       if (err) {
-        // TODO unseed the video
-        logger.error('Cannot insert this video in the database.')
+        // TODO: unseed the video
+        logger.error('Cannot retrieve metadata of the file')
         return next(err)
       }
 
-      // Now we'll add the video's meta data to our friends
-      friends.addVideoToFriends(video_data)
+      const video_data = {
+        name: video_infos.name,
+        namePath: video_file.filename,
+        description: video_infos.description,
+        magnetUri: torrent.magnetURI,
+        author: res.locals.oauth.token.user.username,
+        duration: duration
+      }
+
+      Videos.add(video_data, function (err) {
+        if (err) {
+          // TODO unseed the video
+          logger.error('Cannot insert this video in the database.')
+          return next(err)
+        }
+
+        // Now we'll add the video's meta data to our friends
+        friends.addVideoToFriends(video_data)
 
-      // TODO : include Location of the new video -> 201
-      res.type('json').status(204).end()
+        // TODO : include Location of the new video -> 201
+        res.type('json').status(204).end()
+      })
     })
   })
 }
@@ -144,7 +153,8 @@ function getFormatedVideo (video_obj) {
     podUrl: video_obj.podUrl,
     isLocal: videos.getVideoState(video_obj).owned,
     magnetUri: video_obj.magnetUri,
-    author: video_obj.author
+    author: video_obj.author,
+    duration: video_obj.duration
   }
 
   return formated_video