diff options
Diffstat (limited to 'server/controllers/api/videos.js')
-rw-r--r-- | server/controllers/api/videos.js | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js index e2d393074..2c9e4940e 100644 --- a/server/controllers/api/videos.js +++ b/server/controllers/api/videos.js | |||
@@ -1,8 +1,10 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const express = require('express') | 3 | const express = require('express') |
4 | const fs = require('fs') | ||
4 | const mongoose = require('mongoose') | 5 | const mongoose = require('mongoose') |
5 | const multer = require('multer') | 6 | const multer = require('multer') |
7 | const path = require('path') | ||
6 | const waterfall = require('async/waterfall') | 8 | const waterfall = require('async/waterfall') |
7 | 9 | ||
8 | const constants = require('../../initializers/constants') | 10 | const constants = require('../../initializers/constants') |
@@ -85,11 +87,14 @@ function addVideo (req, res, next) { | |||
85 | const videoInfos = req.body | 87 | const videoInfos = req.body |
86 | 88 | ||
87 | waterfall([ | 89 | waterfall([ |
90 | function createVideoObject (callback) { | ||
91 | const id = mongoose.Types.ObjectId() | ||
88 | 92 | ||
89 | function insertIntoDB (callback) { | ||
90 | const videoData = { | 93 | const videoData = { |
94 | _id: id, | ||
91 | name: videoInfos.name, | 95 | name: videoInfos.name, |
92 | filename: videoFile.filename, | 96 | remoteId: null, |
97 | extname: path.extname(videoFile.filename), | ||
93 | description: videoInfos.description, | 98 | description: videoInfos.description, |
94 | author: res.locals.oauth.token.user.username, | 99 | author: res.locals.oauth.token.user.username, |
95 | duration: videoFile.duration, | 100 | duration: videoFile.duration, |
@@ -97,7 +102,23 @@ function addVideo (req, res, next) { | |||
97 | } | 102 | } |
98 | 103 | ||
99 | const video = new Video(videoData) | 104 | const video = new Video(videoData) |
100 | video.save(function (err, video) { | 105 | |
106 | return callback(null, video) | ||
107 | }, | ||
108 | |||
109 | // Set the videoname the same as the MongoDB id | ||
110 | function renameVideoFile (video, callback) { | ||
111 | const videoDir = constants.CONFIG.STORAGE.VIDEOS_DIR | ||
112 | const source = path.join(videoDir, videoFile.filename) | ||
113 | const destination = path.join(videoDir, video.getFilename()) | ||
114 | |||
115 | fs.rename(source, destination, function (err) { | ||
116 | return callback(err, video) | ||
117 | }) | ||
118 | }, | ||
119 | |||
120 | function insertIntoDB (video, callback) { | ||
121 | video.save(function (err, video, videoFile) { | ||
101 | // Assert there are only one argument sent to the next function (video) | 122 | // Assert there are only one argument sent to the next function (video) |
102 | return callback(err, video) | 123 | return callback(err, video) |
103 | }) | 124 | }) |
@@ -164,7 +185,7 @@ function removeVideo (req, res, next) { | |||
164 | function sendInformationToFriends (video, callback) { | 185 | function sendInformationToFriends (video, callback) { |
165 | const params = { | 186 | const params = { |
166 | name: video.name, | 187 | name: video.name, |
167 | magnetUri: video.magnetUri | 188 | remoteId: video._id |
168 | } | 189 | } |
169 | 190 | ||
170 | friends.removeVideoToFriends(params) | 191 | friends.removeVideoToFriends(params) |