diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/remote.js | 4 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.js | 2 | ||||
-rw-r--r-- | server/models/video.js | 6 | ||||
-rw-r--r-- | server/tests/api/multiple-pods.js | 5 | ||||
-rw-r--r-- | server/tests/api/single-pod.js | 8 | ||||
-rw-r--r-- | server/tests/utils/miscs.js | 6 |
6 files changed, 26 insertions, 5 deletions
diff --git a/server/controllers/api/remote.js b/server/controllers/api/remote.js index 254ae56d5..a36c31c38 100644 --- a/server/controllers/api/remote.js +++ b/server/controllers/api/remote.js | |||
@@ -98,7 +98,8 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) { | |||
98 | description: videoToCreateData.description, | 98 | description: videoToCreateData.description, |
99 | authorId: author.id, | 99 | authorId: author.id, |
100 | duration: videoToCreateData.duration, | 100 | duration: videoToCreateData.duration, |
101 | createdAt: videoToCreateData.createdAt | 101 | createdAt: videoToCreateData.createdAt, |
102 | updatedAt: videoToCreateData.updatedAt | ||
102 | } | 103 | } |
103 | 104 | ||
104 | const video = db.Video.build(videoData) | 105 | const video = db.Video.build(videoData) |
@@ -190,6 +191,7 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) { | |||
190 | videoInstance.set('infoHash', videoAttributesToUpdate.infoHash) | 191 | videoInstance.set('infoHash', videoAttributesToUpdate.infoHash) |
191 | videoInstance.set('duration', videoAttributesToUpdate.duration) | 192 | videoInstance.set('duration', videoAttributesToUpdate.duration) |
192 | videoInstance.set('createdAt', videoAttributesToUpdate.createdAt) | 193 | videoInstance.set('createdAt', videoAttributesToUpdate.createdAt) |
194 | videoInstance.set('updatedAt', videoAttributesToUpdate.updatedAt) | ||
193 | videoInstance.set('extname', videoAttributesToUpdate.extname) | 195 | videoInstance.set('extname', videoAttributesToUpdate.extname) |
194 | 196 | ||
195 | videoInstance.save(options).asCallback(function (err) { | 197 | videoInstance.save(options).asCallback(function (err) { |
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index b76eec1b5..8448386d9 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js | |||
@@ -28,6 +28,7 @@ function isEachRemoteVideosValid (requests) { | |||
28 | isRequestTypeAddValid(request.type) && | 28 | isRequestTypeAddValid(request.type) && |
29 | isVideoAuthorValid(video.author) && | 29 | isVideoAuthorValid(video.author) && |
30 | isVideoDateValid(video.createdAt) && | 30 | isVideoDateValid(video.createdAt) && |
31 | isVideoDateValid(video.updatedAt) && | ||
31 | isVideoDescriptionValid(video.description) && | 32 | isVideoDescriptionValid(video.description) && |
32 | isVideoDurationValid(video.duration) && | 33 | isVideoDurationValid(video.duration) && |
33 | isVideoInfoHashValid(video.infoHash) && | 34 | isVideoInfoHashValid(video.infoHash) && |
@@ -40,6 +41,7 @@ function isEachRemoteVideosValid (requests) { | |||
40 | ( | 41 | ( |
41 | isRequestTypeUpdateValid(request.type) && | 42 | isRequestTypeUpdateValid(request.type) && |
42 | isVideoDateValid(video.createdAt) && | 43 | isVideoDateValid(video.createdAt) && |
44 | isVideoDateValid(video.updatedAt) && | ||
43 | isVideoDescriptionValid(video.description) && | 45 | isVideoDescriptionValid(video.description) && |
44 | isVideoDurationValid(video.duration) && | 46 | isVideoDurationValid(video.duration) && |
45 | isVideoInfoHashValid(video.infoHash) && | 47 | isVideoInfoHashValid(video.infoHash) && |
diff --git a/server/models/video.js b/server/models/video.js index f51d08f06..3fe8368c7 100644 --- a/server/models/video.js +++ b/server/models/video.js | |||
@@ -20,7 +20,6 @@ const customVideosValidators = require('../helpers/custom-validators').videos | |||
20 | // --------------------------------------------------------------------------- | 20 | // --------------------------------------------------------------------------- |
21 | 21 | ||
22 | module.exports = function (sequelize, DataTypes) { | 22 | module.exports = function (sequelize, DataTypes) { |
23 | // TODO: add indexes on searchable columns | ||
24 | const Video = sequelize.define('Video', | 23 | const Video = sequelize.define('Video', |
25 | { | 24 | { |
26 | id: { | 25 | id: { |
@@ -329,7 +328,8 @@ function toFormatedJSON () { | |||
329 | duration: this.duration, | 328 | duration: this.duration, |
330 | tags: map(this.Tags, 'name'), | 329 | tags: map(this.Tags, 'name'), |
331 | thumbnailPath: constants.STATIC_PATHS.THUMBNAILS + '/' + this.getThumbnailName(), | 330 | thumbnailPath: constants.STATIC_PATHS.THUMBNAILS + '/' + this.getThumbnailName(), |
332 | createdAt: this.createdAt | 331 | createdAt: this.createdAt, |
332 | updatedAt: this.updatedAt | ||
333 | } | 333 | } |
334 | 334 | ||
335 | return json | 335 | return json |
@@ -356,6 +356,7 @@ function toAddRemoteJSON (callback) { | |||
356 | thumbnailData: thumbnailData.toString('binary'), | 356 | thumbnailData: thumbnailData.toString('binary'), |
357 | tags: map(self.Tags, 'name'), | 357 | tags: map(self.Tags, 'name'), |
358 | createdAt: self.createdAt, | 358 | createdAt: self.createdAt, |
359 | updatedAt: self.updatedAt, | ||
359 | extname: self.extname | 360 | extname: self.extname |
360 | } | 361 | } |
361 | 362 | ||
@@ -373,6 +374,7 @@ function toUpdateRemoteJSON (callback) { | |||
373 | duration: this.duration, | 374 | duration: this.duration, |
374 | tags: map(this.Tags, 'name'), | 375 | tags: map(this.Tags, 'name'), |
375 | createdAt: this.createdAt, | 376 | createdAt: this.createdAt, |
377 | updatedAt: this.updatedAt, | ||
376 | extname: this.extname | 378 | extname: this.extname |
377 | } | 379 | } |
378 | 380 | ||
diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js index 672187068..4442a7ff7 100644 --- a/server/tests/api/multiple-pods.js +++ b/server/tests/api/multiple-pods.js | |||
@@ -105,6 +105,7 @@ describe('Test multiple pods', function () { | |||
105 | expect(video.duration).to.equal(10) | 105 | expect(video.duration).to.equal(10) |
106 | expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) | 106 | expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) |
107 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 107 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
108 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
108 | expect(video.author).to.equal('root') | 109 | expect(video.author).to.equal('root') |
109 | 110 | ||
110 | if (server.url !== 'http://localhost:9001') { | 111 | if (server.url !== 'http://localhost:9001') { |
@@ -167,6 +168,7 @@ describe('Test multiple pods', function () { | |||
167 | expect(video.duration).to.equal(5) | 168 | expect(video.duration).to.equal(5) |
168 | expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) | 169 | expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) |
169 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 170 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
171 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
170 | expect(video.author).to.equal('root') | 172 | expect(video.author).to.equal('root') |
171 | 173 | ||
172 | if (server.url !== 'http://localhost:9002') { | 174 | if (server.url !== 'http://localhost:9002') { |
@@ -247,6 +249,7 @@ describe('Test multiple pods', function () { | |||
247 | expect(video1.tags).to.deep.equal([ 'tag1p3' ]) | 249 | expect(video1.tags).to.deep.equal([ 'tag1p3' ]) |
248 | expect(video1.author).to.equal('root') | 250 | expect(video1.author).to.equal('root') |
249 | expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true | 251 | expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true |
252 | expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true | ||
250 | 253 | ||
251 | expect(video2.name).to.equal('my super name for pod 3-2') | 254 | expect(video2.name).to.equal('my super name for pod 3-2') |
252 | expect(video2.description).to.equal('my super description for pod 3-2') | 255 | expect(video2.description).to.equal('my super description for pod 3-2') |
@@ -256,6 +259,7 @@ describe('Test multiple pods', function () { | |||
256 | expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) | 259 | expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) |
257 | expect(video2.author).to.equal('root') | 260 | expect(video2.author).to.equal('root') |
258 | expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true | 261 | expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true |
262 | expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true | ||
259 | 263 | ||
260 | if (server.url !== 'http://localhost:9003') { | 264 | if (server.url !== 'http://localhost:9003') { |
261 | expect(video1.isLocal).to.be.false | 265 | expect(video1.isLocal).to.be.false |
@@ -398,6 +402,7 @@ describe('Test multiple pods', function () { | |||
398 | expect(!!videoUpdated).to.be.true | 402 | expect(!!videoUpdated).to.be.true |
399 | expect(videoUpdated.description).to.equal('my super description updated') | 403 | expect(videoUpdated.description).to.equal('my super description updated') |
400 | expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | 404 | expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) |
405 | expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true | ||
401 | 406 | ||
402 | callback() | 407 | callback() |
403 | }) | 408 | }) |
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js index 57146900d..29512dfc6 100644 --- a/server/tests/api/single-pod.js +++ b/server/tests/api/single-pod.js | |||
@@ -83,6 +83,7 @@ describe('Test a single pod', function () { | |||
83 | expect(video.isLocal).to.be.true | 83 | expect(video.isLocal).to.be.true |
84 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | 84 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
85 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 85 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
86 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
86 | 87 | ||
87 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | 88 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
88 | if (err) throw err | 89 | if (err) throw err |
@@ -117,6 +118,7 @@ describe('Test a single pod', function () { | |||
117 | expect(video.isLocal).to.be.true | 118 | expect(video.isLocal).to.be.true |
118 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | 119 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
119 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 120 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
121 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
120 | 122 | ||
121 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | 123 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
122 | if (err) throw err | 124 | if (err) throw err |
@@ -143,6 +145,7 @@ describe('Test a single pod', function () { | |||
143 | expect(video.isLocal).to.be.true | 145 | expect(video.isLocal).to.be.true |
144 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | 146 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
145 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 147 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
148 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
146 | 149 | ||
147 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | 150 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
148 | if (err) throw err | 151 | if (err) throw err |
@@ -170,6 +173,7 @@ describe('Test a single pod', function () { | |||
170 | // expect(video.isLocal).to.be.true | 173 | // expect(video.isLocal).to.be.true |
171 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | 174 | // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
172 | // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 175 | // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
176 | // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
173 | 177 | ||
174 | // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | 178 | // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
175 | // if (err) throw err | 179 | // if (err) throw err |
@@ -196,6 +200,7 @@ describe('Test a single pod', function () { | |||
196 | expect(video.isLocal).to.be.true | 200 | expect(video.isLocal).to.be.true |
197 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) | 201 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) |
198 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 202 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
203 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
199 | 204 | ||
200 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { | 205 | videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { |
201 | if (err) throw err | 206 | if (err) throw err |
@@ -522,6 +527,7 @@ describe('Test a single pod', function () { | |||
522 | expect(video.isLocal).to.be.true | 527 | expect(video.isLocal).to.be.true |
523 | expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) | 528 | expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) |
524 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 529 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
530 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
525 | 531 | ||
526 | done() | 532 | done() |
527 | }) | 533 | }) |
@@ -545,6 +551,7 @@ describe('Test a single pod', function () { | |||
545 | expect(video.isLocal).to.be.true | 551 | expect(video.isLocal).to.be.true |
546 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | 552 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) |
547 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 553 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
554 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
548 | 555 | ||
549 | done() | 556 | done() |
550 | }) | 557 | }) |
@@ -569,6 +576,7 @@ describe('Test a single pod', function () { | |||
569 | expect(video.isLocal).to.be.true | 576 | expect(video.isLocal).to.be.true |
570 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) | 577 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ]) |
571 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true | 578 | expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true |
579 | expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true | ||
572 | 580 | ||
573 | done() | 581 | done() |
574 | }) | 582 | }) |
diff --git a/server/tests/utils/miscs.js b/server/tests/utils/miscs.js index 4ceff65df..c4b661496 100644 --- a/server/tests/utils/miscs.js +++ b/server/tests/utils/miscs.js | |||
@@ -6,12 +6,14 @@ const miscsUtils = { | |||
6 | 6 | ||
7 | // ---------------------- Export functions -------------------- | 7 | // ---------------------- Export functions -------------------- |
8 | 8 | ||
9 | function dateIsValid (dateString) { | 9 | function dateIsValid (dateString, interval) { |
10 | const dateToCheck = new Date(dateString) | 10 | const dateToCheck = new Date(dateString) |
11 | const now = new Date() | 11 | const now = new Date() |
12 | 12 | ||
13 | // Check if the interval is more than 2 minutes | 13 | // Check if the interval is more than 2 minutes |
14 | if (now - dateToCheck > 120000) return false | 14 | if (!interval) interval = 120000 |
15 | |||
16 | if (now - dateToCheck > interval) return false | ||
15 | 17 | ||
16 | return true | 18 | return true |
17 | } | 19 | } |