aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/api/v1/videos.js7
-rw-r--r--server/helpers/customValidators.js3
-rw-r--r--server/models/videos.js10
-rw-r--r--server/tests/api/multiplePods.js4
-rw-r--r--server/tests/api/singlePod.js3
-rw-r--r--server/tests/api/utils.js11
6 files changed, 32 insertions, 6 deletions
diff --git a/server/controllers/api/v1/videos.js b/server/controllers/api/v1/videos.js
index 0e058836e..5bdfdbf58 100644
--- a/server/controllers/api/v1/videos.js
+++ b/server/controllers/api/v1/videos.js
@@ -111,13 +111,15 @@ function addVideo (req, res, next) {
111 thumbnail: thumbnailName 111 thumbnail: thumbnailName
112 } 112 }
113 113
114 Videos.add(videoData, function (err) { 114 Videos.add(videoData, function (err, insertedVideo) {
115 if (err) { 115 if (err) {
116 // TODO unseed the video 116 // TODO unseed the video
117 logger.error('Cannot insert this video in the database.') 117 logger.error('Cannot insert this video in the database.')
118 return next(err) 118 return next(err)
119 } 119 }
120 120
121 videoData.createdDate = insertedVideo.createdDate
122
121 fs.readFile(thumbnailsDir + thumbnailName, function (err, data) { 123 fs.readFile(thumbnailsDir + thumbnailName, function (err, data) {
122 if (err) { 124 if (err) {
123 // TODO: remove video? 125 // TODO: remove video?
@@ -205,7 +207,8 @@ function getFormatedVideo (videoObj) {
205 magnetUri: videoObj.magnetUri, 207 magnetUri: videoObj.magnetUri,
206 author: videoObj.author, 208 author: videoObj.author,
207 duration: videoObj.duration, 209 duration: videoObj.duration,
208 thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + videoObj.thumbnail 210 thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + videoObj.thumbnail,
211 createdDate: videoObj.createdDate
209 } 212 }
210 213
211 return formatedVideo 214 return formatedVideo
diff --git a/server/helpers/customValidators.js b/server/helpers/customValidators.js
index 0fbabab52..a8fc6942d 100644
--- a/server/helpers/customValidators.js
+++ b/server/helpers/customValidators.js
@@ -14,7 +14,8 @@ function eachIsRemoteVideosAddValid (values) {
14 validator.isLength(val.description, 1, 50) && 14 validator.isLength(val.description, 1, 50) &&
15 validator.isLength(val.magnetUri, 10) && 15 validator.isLength(val.magnetUri, 10) &&
16 validator.isURL(val.podUrl) && 16 validator.isURL(val.podUrl) &&
17 !isNaN(val.duration) 17 !isNaN(val.duration) &&
18 validator.isDate(val.createdDate)
18 }) 19 })
19} 20}
20 21
diff --git a/server/models/videos.js b/server/models/videos.js
index aa9ed687d..250ad3952 100644
--- a/server/models/videos.js
+++ b/server/models/videos.js
@@ -19,7 +19,11 @@ const videosSchema = mongoose.Schema({
19 podUrl: String, 19 podUrl: String,
20 author: String, 20 author: String,
21 duration: Number, 21 duration: Number,
22 thumbnail: String 22 thumbnail: String,
23 createdDate: {
24 type: Date,
25 default: Date.now
26 }
23}) 27})
24const VideosDB = mongoose.model('videos', videosSchema) 28const VideosDB = mongoose.model('videos', videosSchema)
25 29
@@ -46,13 +50,13 @@ function add (video, callback) {
46 const params = video 50 const params = video
47 params.podUrl = http + '://' + host + ':' + port 51 params.podUrl = http + '://' + host + ':' + port
48 52
49 VideosDB.create(params, function (err, video) { 53 VideosDB.create(params, function (err, insertedVideo) {
50 if (err) { 54 if (err) {
51 logger.error('Cannot insert this video into database.') 55 logger.error('Cannot insert this video into database.')
52 return callback(err) 56 return callback(err)
53 } 57 }
54 58
55 callback(null) 59 callback(null, insertedVideo)
56 }) 60 })
57} 61}
58 62
diff --git a/server/tests/api/multiplePods.js b/server/tests/api/multiplePods.js
index 51e7fb3d1..c31c18b02 100644
--- a/server/tests/api/multiplePods.js
+++ b/server/tests/api/multiplePods.js
@@ -98,6 +98,7 @@ describe('Test multiple pods', function () {
98 expect(video.podUrl).to.equal('http://localhost:9001') 98 expect(video.podUrl).to.equal('http://localhost:9001')
99 expect(video.magnetUri).to.exist 99 expect(video.magnetUri).to.exist
100 expect(video.duration).to.equal(10) 100 expect(video.duration).to.equal(10)
101 expect(utils.dateIsValid(video.createdDate)).to.be.true
101 102
102 if (server.url !== 'http://localhost:9001') { 103 if (server.url !== 'http://localhost:9001') {
103 expect(video.isLocal).to.be.false 104 expect(video.isLocal).to.be.false
@@ -153,6 +154,7 @@ describe('Test multiple pods', function () {
153 expect(video.podUrl).to.equal('http://localhost:9002') 154 expect(video.podUrl).to.equal('http://localhost:9002')
154 expect(video.magnetUri).to.exist 155 expect(video.magnetUri).to.exist
155 expect(video.duration).to.equal(5) 156 expect(video.duration).to.equal(5)
157 expect(utils.dateIsValid(video.createdDate)).to.be.true
156 158
157 if (server.url !== 'http://localhost:9002') { 159 if (server.url !== 'http://localhost:9002') {
158 expect(video.isLocal).to.be.false 160 expect(video.isLocal).to.be.false
@@ -221,12 +223,14 @@ describe('Test multiple pods', function () {
221 expect(video1.podUrl).to.equal('http://localhost:9003') 223 expect(video1.podUrl).to.equal('http://localhost:9003')
222 expect(video1.magnetUri).to.exist 224 expect(video1.magnetUri).to.exist
223 expect(video1.duration).to.equal(5) 225 expect(video1.duration).to.equal(5)
226 expect(utils.dateIsValid(video1.createdDate)).to.be.true
224 227
225 expect(video2.name).to.equal('my super name for pod 3-2') 228 expect(video2.name).to.equal('my super name for pod 3-2')
226 expect(video2.description).to.equal('my super description for pod 3-2') 229 expect(video2.description).to.equal('my super description for pod 3-2')
227 expect(video2.podUrl).to.equal('http://localhost:9003') 230 expect(video2.podUrl).to.equal('http://localhost:9003')
228 expect(video2.magnetUri).to.exist 231 expect(video2.magnetUri).to.exist
229 expect(video2.duration).to.equal(5) 232 expect(video2.duration).to.equal(5)
233 expect(utils.dateIsValid(video2.createdDate)).to.be.true
230 234
231 if (server.url !== 'http://localhost:9003') { 235 if (server.url !== 'http://localhost:9003') {
232 expect(video1.isLocal).to.be.false 236 expect(video1.isLocal).to.be.false
diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js
index d377bdf45..72002b631 100644
--- a/server/tests/api/singlePod.js
+++ b/server/tests/api/singlePod.js
@@ -76,6 +76,7 @@ describe('Test a single pod', function () {
76 expect(video.magnetUri).to.exist 76 expect(video.magnetUri).to.exist
77 expect(video.author).to.equal('root') 77 expect(video.author).to.equal('root')
78 expect(video.isLocal).to.be.true 78 expect(video.isLocal).to.be.true
79 expect(utils.dateIsValid(video.createdDate)).to.be.true
79 80
80 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 81 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
81 if (err) throw err 82 if (err) throw err
@@ -109,6 +110,7 @@ describe('Test a single pod', function () {
109 expect(video.magnetUri).to.exist 110 expect(video.magnetUri).to.exist
110 expect(video.author).to.equal('root') 111 expect(video.author).to.equal('root')
111 expect(video.isLocal).to.be.true 112 expect(video.isLocal).to.be.true
113 expect(utils.dateIsValid(video.createdDate)).to.be.true
112 114
113 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 115 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
114 if (err) throw err 116 if (err) throw err
@@ -138,6 +140,7 @@ describe('Test a single pod', function () {
138 expect(video.podUrl).to.equal('http://localhost:9001') 140 expect(video.podUrl).to.equal('http://localhost:9001')
139 expect(video.author).to.equal('root') 141 expect(video.author).to.equal('root')
140 expect(video.isLocal).to.be.true 142 expect(video.isLocal).to.be.true
143 expect(utils.dateIsValid(video.createdDate)).to.be.true
141 144
142 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 145 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
143 if (err) throw err 146 if (err) throw err
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js
index f0b1c3653..d505cb5d9 100644
--- a/server/tests/api/utils.js
+++ b/server/tests/api/utils.js
@@ -8,6 +8,7 @@ const pathUtils = require('path')
8const request = require('supertest') 8const request = require('supertest')
9 9
10const testUtils = { 10const testUtils = {
11 dateIsValid: dateIsValid,
11 flushTests: flushTests, 12 flushTests: flushTests,
12 getFriendsList: getFriendsList, 13 getFriendsList: getFriendsList,
13 getVideo: getVideo, 14 getVideo: getVideo,
@@ -28,6 +29,16 @@ const testUtils = {
28 29
29// ---------------------- Export functions -------------------- 30// ---------------------- Export functions --------------------
30 31
32function dateIsValid (dateString) {
33 const dateToCheck = new Date(dateString)
34 const now = new Date()
35
36 // Check if the interval is more than 2 minutes
37 if (now - dateToCheck > 120000) return false
38
39 return true
40}
41
31function flushTests (callback) { 42function flushTests (callback) {
32 exec('npm run clean:server:test', callback) 43 exec('npm run clean:server:test', callback)
33} 44}