aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-16 19:49:10 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-16 19:49:10 +0200
commit67100f1f971dd10a466a321899b56c0813e08d31 (patch)
tree3253db23a9dca2273fd2c9702fb3b6f1801c0f1c /server/controllers/api
parentdcc7b3fe470fe5f1546c0f3e7c28c07fc54633c5 (diff)
downloadPeerTube-67100f1f971dd10a466a321899b56c0813e08d31.tar.gz
PeerTube-67100f1f971dd10a466a321899b56c0813e08d31.tar.zst
PeerTube-67100f1f971dd10a466a321899b56c0813e08d31.zip
Add a check for the duration of videos
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/v1/videos.js26
1 files changed, 7 insertions, 19 deletions
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index 231309c5e..c6dbfbaf2 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -83,23 +83,11 @@ function addVideo (req, res, next) {
83 const videoInfos = req.body 83 const videoInfos = req.body
84 84
85 async.waterfall([ 85 async.waterfall([
86 function (callback) { 86 function seedTheVideo (callback) {
87 videos.seed(videoFile.path, callback) 87 videos.seed(videoFile.path, callback)
88 }, 88 },
89 89
90 function seed (torrent, callback) { 90 function createThumbnail (torrent, callback) {
91 videos.getVideoDuration(videoFile.path, function (err, duration) {
92 if (err) {
93 // TODO: unseed the video
94 logger.error('Cannot retrieve metadata of the file.')
95 return next(err)
96 }
97
98 callback(null, torrent, duration)
99 })
100 },
101
102 function createThumbnail (torrent, duration, callback) {
103 videos.createVideoThumbnail(videoFile.path, function (err, thumbnailName) { 91 videos.createVideoThumbnail(videoFile.path, function (err, thumbnailName) {
104 if (err) { 92 if (err) {
105 // TODO: unseed the video 93 // TODO: unseed the video
@@ -107,18 +95,18 @@ function addVideo (req, res, next) {
107 return callback(err) 95 return callback(err)
108 } 96 }
109 97
110 callback(null, torrent, duration, thumbnailName) 98 callback(null, torrent, thumbnailName)
111 }) 99 })
112 }, 100 },
113 101
114 function insertIntoDB (torrent, duration, thumbnailName, callback) { 102 function insertIntoDB (torrent, thumbnailName, callback) {
115 const videoData = { 103 const videoData = {
116 name: videoInfos.name, 104 name: videoInfos.name,
117 namePath: videoFile.filename, 105 namePath: videoFile.filename,
118 description: videoInfos.description, 106 description: videoInfos.description,
119 magnetUri: torrent.magnetURI, 107 magnetUri: torrent.magnetURI,
120 author: res.locals.oauth.token.user.username, 108 author: res.locals.oauth.token.user.username,
121 duration: duration, 109 duration: videoFile.duration,
122 thumbnail: thumbnailName 110 thumbnail: thumbnailName
123 } 111 }
124 112
@@ -130,11 +118,11 @@ function addVideo (req, res, next) {
130 return callback(err) 118 return callback(err)
131 } 119 }
132 120
133 return callback(null, torrent, duration, thumbnailName, videoData, insertedVideo) 121 return callback(null, torrent, thumbnailName, videoData, insertedVideo)
134 }) 122 })
135 }, 123 },
136 124
137 function getThumbnailBase64 (torrent, duration, thumbnailName, videoData, insertedVideo, callback) { 125 function getThumbnailBase64 (torrent, thumbnailName, videoData, insertedVideo, callback) {
138 videoData.createdDate = insertedVideo.createdDate 126 videoData.createdDate = insertedVideo.createdDate
139 127
140 fs.readFile(thumbnailsDir + thumbnailName, function (err, thumbnailData) { 128 fs.readFile(thumbnailsDir + thumbnailName, function (err, thumbnailData) {