diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/remote.js | 2 | ||||
-rw-r--r-- | server/controllers/api/videos.js | 29 |
2 files changed, 26 insertions, 5 deletions
diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.js index 17b1d07c4..94808693d 100644 --- a/server/controllers/api/remote.js +++ b/server/controllers/api/remote.js | |||
@@ -64,7 +64,7 @@ function addRemoteVideo (videoToCreateData, callback) { | |||
64 | 64 | ||
65 | function removeRemoteVideo (videoToRemoveData, fromUrl, callback) { | 65 | function removeRemoteVideo (videoToRemoveData, fromUrl, callback) { |
66 | // We need the list because we have to remove some other stuffs (thumbnail etc) | 66 | // We need the list because we have to remove some other stuffs (thumbnail etc) |
67 | Video.listByUrlAndMagnet(fromUrl, videoToRemoveData.magnetUri, function (err, videosList) { | 67 | Video.listByUrlAndRemoteId(fromUrl, videoToRemoveData.remoteId, function (err, videosList) { |
68 | if (err) { | 68 | if (err) { |
69 | logger.error('Cannot list videos from url and magnets.', { error: err }) | 69 | logger.error('Cannot list videos from url and magnets.', { error: err }) |
70 | return callback(err) | 70 | return callback(err) |
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) |