aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-03-27 20:53:11 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-03-27 20:53:11 +0200
commit6f0c39e2de400685b7baf8340b9e132f2659365a (patch)
treeb036c6ebf65ff4cb7f5649fc48a0b7201370bddd
parent28974889281523eec5b00dd5596c67d99c5167e5 (diff)
downloadPeerTube-6f0c39e2de400685b7baf8340b9e132f2659365a.tar.gz
PeerTube-6f0c39e2de400685b7baf8340b9e132f2659365a.tar.zst
PeerTube-6f0c39e2de400685b7baf8340b9e132f2659365a.zip
Server: add licence video attribute
-rw-r--r--server/controllers/api/remote/videos.js2
-rw-r--r--server/controllers/api/videos.js7
-rw-r--r--server/helpers/custom-validators/remote/videos.js1
-rw-r--r--server/helpers/custom-validators/videos.js5
-rw-r--r--server/initializers/constants.js14
-rw-r--r--server/initializers/migrations/0035-video-licence.js34
-rw-r--r--server/middlewares/validators/videos.js2
-rw-r--r--server/models/video.js18
-rw-r--r--server/tests/api/check-params/videos.js59
-rw-r--r--server/tests/api/multiple-pods.js16
-rw-r--r--server/tests/api/single-pod.js30
-rw-r--r--server/tests/real-world/real-world.js1
-rw-r--r--server/tests/real-world/tools/upload.js8
-rw-r--r--server/tests/utils/videos.js15
14 files changed, 209 insertions, 3 deletions
diff --git a/server/controllers/api/remote/videos.js b/server/controllers/api/remote/videos.js
index c8ef0c445..a3e1189c7 100644
--- a/server/controllers/api/remote/videos.js
+++ b/server/controllers/api/remote/videos.js
@@ -295,6 +295,7 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) {
295 extname: videoToCreateData.extname, 295 extname: videoToCreateData.extname,
296 infoHash: videoToCreateData.infoHash, 296 infoHash: videoToCreateData.infoHash,
297 category: videoToCreateData.category, 297 category: videoToCreateData.category,
298 licence: videoToCreateData.licence,
298 description: videoToCreateData.description, 299 description: videoToCreateData.description,
299 authorId: author.id, 300 authorId: author.id,
300 duration: videoToCreateData.duration, 301 duration: videoToCreateData.duration,
@@ -392,6 +393,7 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) {
392 393
393 videoInstance.set('name', videoAttributesToUpdate.name) 394 videoInstance.set('name', videoAttributesToUpdate.name)
394 videoInstance.set('category', videoAttributesToUpdate.category) 395 videoInstance.set('category', videoAttributesToUpdate.category)
396 videoInstance.set('licence', videoAttributesToUpdate.licence)
395 videoInstance.set('description', videoAttributesToUpdate.description) 397 videoInstance.set('description', videoAttributesToUpdate.description)
396 videoInstance.set('infoHash', videoAttributesToUpdate.infoHash) 398 videoInstance.set('infoHash', videoAttributesToUpdate.infoHash)
397 videoInstance.set('duration', videoAttributesToUpdate.duration) 399 videoInstance.set('duration', videoAttributesToUpdate.duration)
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index 8c69ff4e5..375e89387 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -46,6 +46,7 @@ const storage = multer.diskStorage({
46const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) 46const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
47 47
48router.get('/categories', listVideoCategories) 48router.get('/categories', listVideoCategories)
49router.get('/licences', listVideoLicences)
49 50
50router.get('/abuse', 51router.get('/abuse',
51 oAuth.authenticate, 52 oAuth.authenticate,
@@ -116,6 +117,10 @@ function listVideoCategories (req, res, next) {
116 res.json(constants.VIDEO_CATEGORIES) 117 res.json(constants.VIDEO_CATEGORIES)
117} 118}
118 119
120function listVideoLicences (req, res, next) {
121 res.json(constants.VIDEO_LICENCES)
122}
123
119function rateVideoRetryWrapper (req, res, next) { 124function rateVideoRetryWrapper (req, res, next) {
120 const options = { 125 const options = {
121 arguments: [ req, res ], 126 arguments: [ req, res ],
@@ -307,6 +312,7 @@ function addVideo (req, res, videoFile, finalCallback) {
307 remoteId: null, 312 remoteId: null,
308 extname: path.extname(videoFile.filename), 313 extname: path.extname(videoFile.filename),
309 category: videoInfos.category, 314 category: videoInfos.category,
315 licence: videoInfos.licence,
310 description: videoInfos.description, 316 description: videoInfos.description,
311 duration: videoFile.duration, 317 duration: videoFile.duration,
312 authorId: author.id 318 authorId: author.id
@@ -421,6 +427,7 @@ function updateVideo (req, res, finalCallback) {
421 427
422 if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name) 428 if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name)
423 if (videoInfosToUpdate.category) videoInstance.set('category', videoInfosToUpdate.category) 429 if (videoInfosToUpdate.category) videoInstance.set('category', videoInfosToUpdate.category)
430 if (videoInfosToUpdate.licence) videoInstance.set('licence', videoInfosToUpdate.licence)
424 if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description) 431 if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description)
425 432
426 videoInstance.save(options).asCallback(function (err) { 433 videoInstance.save(options).asCallback(function (err) {
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js
index 701acdbfd..9a9055676 100644
--- a/server/helpers/custom-validators/remote/videos.js
+++ b/server/helpers/custom-validators/remote/videos.js
@@ -86,6 +86,7 @@ function isCommonVideoAttributesValid (video) {
86 return videosValidators.isVideoDateValid(video.createdAt) && 86 return videosValidators.isVideoDateValid(video.createdAt) &&
87 videosValidators.isVideoDateValid(video.updatedAt) && 87 videosValidators.isVideoDateValid(video.updatedAt) &&
88 videosValidators.isVideoCategoryValid(video.category) && 88 videosValidators.isVideoCategoryValid(video.category) &&
89 videosValidators.isVideoLicenceValid(video.licence) &&
89 videosValidators.isVideoDescriptionValid(video.description) && 90 videosValidators.isVideoDescriptionValid(video.description) &&
90 videosValidators.isVideoDurationValid(video.duration) && 91 videosValidators.isVideoDurationValid(video.duration) &&
91 videosValidators.isVideoInfoHashValid(video.infoHash) && 92 videosValidators.isVideoInfoHashValid(video.infoHash) &&
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js
index efa89c427..8495e9665 100644
--- a/server/helpers/custom-validators/videos.js
+++ b/server/helpers/custom-validators/videos.js
@@ -14,6 +14,7 @@ const videosValidators = {
14 isVideoAuthorValid, 14 isVideoAuthorValid,
15 isVideoDateValid, 15 isVideoDateValid,
16 isVideoCategoryValid, 16 isVideoCategoryValid,
17 isVideoLicenceValid,
17 isVideoDescriptionValid, 18 isVideoDescriptionValid,
18 isVideoDurationValid, 19 isVideoDurationValid,
19 isVideoInfoHashValid, 20 isVideoInfoHashValid,
@@ -45,6 +46,10 @@ function isVideoCategoryValid (value) {
45 return constants.VIDEO_CATEGORIES[value] !== undefined 46 return constants.VIDEO_CATEGORIES[value] !== undefined
46} 47}
47 48
49function isVideoLicenceValid (value) {
50 return constants.VIDEO_LICENCES[value] !== undefined
51}
52
48function isVideoDescriptionValid (value) { 53function isVideoDescriptionValid (value) {
49 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION) 54 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)
50} 55}
diff --git a/server/initializers/constants.js b/server/initializers/constants.js
index 40f01e389..af494cb66 100644
--- a/server/initializers/constants.js
+++ b/server/initializers/constants.js
@@ -5,7 +5,7 @@ const path = require('path')
5 5
6// --------------------------------------------------------------------------- 6// ---------------------------------------------------------------------------
7 7
8const LAST_MIGRATION_VERSION = 30 8const LAST_MIGRATION_VERSION = 35
9 9
10// --------------------------------------------------------------------------- 10// ---------------------------------------------------------------------------
11 11
@@ -124,6 +124,17 @@ const VIDEO_CATEGORIES = {
124 18: 'Food' 124 18: 'Food'
125} 125}
126 126
127// See https://creativecommons.org/licenses/?lang=en
128const VIDEO_LICENCES = {
129 1: 'Attribution',
130 2: 'Attribution - Share Alike',
131 3: 'Attribution - No Derivatives',
132 4: 'Attribution - Non Commercial',
133 5: 'Attribution - Non Commercial - Share Alike',
134 6: 'Attribution - Non Commercial - No Derivatives',
135 7: 'Public Domain Dedication'
136}
137
127// --------------------------------------------------------------------------- 138// ---------------------------------------------------------------------------
128 139
129// Score a pod has when we create it as a friend 140// Score a pod has when we create it as a friend
@@ -280,6 +291,7 @@ module.exports = {
280 THUMBNAILS_SIZE, 291 THUMBNAILS_SIZE,
281 USER_ROLES, 292 USER_ROLES,
282 VIDEO_CATEGORIES, 293 VIDEO_CATEGORIES,
294 VIDEO_LICENCES,
283 VIDEO_RATE_TYPES 295 VIDEO_RATE_TYPES
284} 296}
285 297
diff --git a/server/initializers/migrations/0035-video-licence.js b/server/initializers/migrations/0035-video-licence.js
new file mode 100644
index 000000000..9cf75858d
--- /dev/null
+++ b/server/initializers/migrations/0035-video-licence.js
@@ -0,0 +1,34 @@
1'use strict'
2
3const waterfall = require('async/waterfall')
4
5// utils = { transaction, queryInterface, sequelize, Sequelize }
6exports.up = function (utils, finalCallback) {
7 const q = utils.queryInterface
8 const Sequelize = utils.Sequelize
9
10 const data = {
11 type: Sequelize.INTEGER,
12 allowNull: false,
13 defaultValue: 0
14 }
15
16 waterfall([
17
18 function addLicenceColumn (callback) {
19 q.addColumn('Videos', 'licence', data, { transaction: utils.transaction }).asCallback(function (err) {
20 return callback(err)
21 })
22 },
23
24 function nullOnDefault (callback) {
25 data.defaultValue = null
26
27 q.changeColumn('Videos', 'licence', data, { transaction: utils.transaction }).asCallback(callback)
28 }
29 ], finalCallback)
30}
31
32exports.down = function (options, callback) {
33 throw new Error('Not implemented.')
34}
diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js
index cf3874a97..6cc0c2565 100644
--- a/server/middlewares/validators/videos.js
+++ b/server/middlewares/validators/videos.js
@@ -22,6 +22,7 @@ function videosAdd (req, res, next) {
22 req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files) 22 req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files)
23 req.checkBody('name', 'Should have a valid name').isVideoNameValid() 23 req.checkBody('name', 'Should have a valid name').isVideoNameValid()
24 req.checkBody('category', 'Should have a valid category').isVideoCategoryValid() 24 req.checkBody('category', 'Should have a valid category').isVideoCategoryValid()
25 req.checkBody('licence', 'Should have a valid licence').isVideoLicenceValid()
25 req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid() 26 req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
26 req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid() 27 req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()
27 28
@@ -49,6 +50,7 @@ function videosUpdate (req, res, next) {
49 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) 50 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
50 req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid() 51 req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid()
51 req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid() 52 req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid()
53 req.checkBody('licence', 'Should have a valid licence').optional().isVideoLicenceValid()
52 req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid() 54 req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid()
53 req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid() 55 req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()
54 56
diff --git a/server/models/video.js b/server/models/video.js
index c4c7b5de8..0f44b98c3 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -61,6 +61,16 @@ module.exports = function (sequelize, DataTypes) {
61 } 61 }
62 } 62 }
63 }, 63 },
64 licence: {
65 type: DataTypes.INTEGER,
66 allowNull: false,
67 validate: {
68 licenceValid: function (value) {
69 const res = customVideosValidators.isVideoLicenceValid(value)
70 if (res === false) throw new Error('Video licence is not valid.')
71 }
72 }
73 },
64 description: { 74 description: {
65 type: DataTypes.STRING, 75 type: DataTypes.STRING,
66 allowNull: false, 76 allowNull: false,
@@ -374,11 +384,17 @@ function toFormatedJSON () {
374 let categoryLabel = constants.VIDEO_CATEGORIES[this.category] 384 let categoryLabel = constants.VIDEO_CATEGORIES[this.category]
375 if (!categoryLabel) categoryLabel = 'Misc' 385 if (!categoryLabel) categoryLabel = 'Misc'
376 386
387 // Maybe our pod is not up to date and there are new licences since our version
388 let licenceLabel = constants.VIDEO_LICENCES[this.licence]
389 if (!licenceLabel) licenceLabel = 'Unknown'
390
377 const json = { 391 const json = {
378 id: this.id, 392 id: this.id,
379 name: this.name, 393 name: this.name,
380 category: this.category, 394 category: this.category,
381 categoryLabel, 395 categoryLabel,
396 licence: this.licence,
397 licenceLabel,
382 description: this.description, 398 description: this.description,
383 podHost, 399 podHost,
384 isLocal: this.isOwned(), 400 isLocal: this.isOwned(),
@@ -411,6 +427,7 @@ function toAddRemoteJSON (callback) {
411 const remoteVideo = { 427 const remoteVideo = {
412 name: self.name, 428 name: self.name,
413 category: self.category, 429 category: self.category,
430 licence: self.licence,
414 description: self.description, 431 description: self.description,
415 infoHash: self.infoHash, 432 infoHash: self.infoHash,
416 remoteId: self.id, 433 remoteId: self.id,
@@ -434,6 +451,7 @@ function toUpdateRemoteJSON (callback) {
434 const json = { 451 const json = {
435 name: this.name, 452 name: this.name,
436 category: this.category, 453 category: this.category,
454 licence: this.licence,
437 description: this.description, 455 description: this.description,
438 infoHash: this.infoHash, 456 infoHash: this.infoHash,
439 remoteId: this.id, 457 remoteId: this.id,
diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js
index 03b4db3fe..e58f9893b 100644
--- a/server/tests/api/check-params/videos.js
+++ b/server/tests/api/check-params/videos.js
@@ -113,6 +113,7 @@ describe('Test videos API validator', function () {
113 it('Should fail without name', function (done) { 113 it('Should fail without name', function (done) {
114 const data = { 114 const data = {
115 category: 5, 115 category: 5,
116 licence: 1,
116 description: 'my super description', 117 description: 'my super description',
117 tags: [ 'tag1', 'tag2' ] 118 tags: [ 'tag1', 'tag2' ]
118 } 119 }
@@ -126,6 +127,7 @@ describe('Test videos API validator', function () {
126 const data = { 127 const data = {
127 name: 'My very very very very very very very very very very very very very very very very long name', 128 name: 'My very very very very very very very very very very very very very very very very long name',
128 category: 5, 129 category: 5,
130 licence: 1,
129 description: 'my super description', 131 description: 'my super description',
130 tags: [ 'tag1', 'tag2' ] 132 tags: [ 'tag1', 'tag2' ]
131 } 133 }
@@ -138,6 +140,7 @@ describe('Test videos API validator', function () {
138 it('Should fail without a category', function (done) { 140 it('Should fail without a category', function (done) {
139 const data = { 141 const data = {
140 name: 'my super name', 142 name: 'my super name',
143 licence: 1,
141 description: 'my super description', 144 description: 'my super description',
142 tags: [ 'tag1', 'tag2' ] 145 tags: [ 'tag1', 'tag2' ]
143 } 146 }
@@ -151,6 +154,34 @@ describe('Test videos API validator', function () {
151 const data = { 154 const data = {
152 name: 'my super name', 155 name: 'my super name',
153 category: 125, 156 category: 125,
157 licence: 1,
158 description: 'my super description',
159 tags: [ 'tag1', 'tag2' ]
160 }
161 const attach = {
162 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
163 }
164 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
165 })
166
167 it('Should fail without a licence', function (done) {
168 const data = {
169 name: 'my super name',
170 category: 5,
171 description: 'my super description',
172 tags: [ 'tag1', 'tag2' ]
173 }
174 const attach = {
175 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
176 }
177 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
178 })
179
180 it('Should fail with a bad licence', function (done) {
181 const data = {
182 name: 'my super name',
183 category: 5,
184 licence: 125,
154 description: 'my super description', 185 description: 'my super description',
155 tags: [ 'tag1', 'tag2' ] 186 tags: [ 'tag1', 'tag2' ]
156 } 187 }
@@ -164,6 +195,7 @@ describe('Test videos API validator', function () {
164 const data = { 195 const data = {
165 name: 'my super name', 196 name: 'my super name',
166 category: 5, 197 category: 5,
198 licence: 1,
167 tags: [ 'tag1', 'tag2' ] 199 tags: [ 'tag1', 'tag2' ]
168 } 200 }
169 const attach = { 201 const attach = {
@@ -176,6 +208,7 @@ describe('Test videos API validator', function () {
176 const data = { 208 const data = {
177 name: 'my super name', 209 name: 'my super name',
178 category: 5, 210 category: 5,
211 licence: 1,
179 description: 'my super description which is very very very very very very very very very very very very very very' + 212 description: 'my super description which is very very very very very very very very very very very very very very' +
180 'very very very very very very very very very very very very very very very very very very very very very' + 213 'very very very very very very very very very very very very very very very very very very very very very' +
181 'very very very very very very very very very very very very very very very long', 214 'very very very very very very very very very very very very very very very long',
@@ -191,6 +224,7 @@ describe('Test videos API validator', function () {
191 const data = { 224 const data = {
192 name: 'my super name', 225 name: 'my super name',
193 category: 5, 226 category: 5,
227 licence: 1,
194 description: 'my super description', 228 description: 'my super description',
195 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] 229 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
196 } 230 }
@@ -204,6 +238,7 @@ describe('Test videos API validator', function () {
204 const data = { 238 const data = {
205 name: 'my super name', 239 name: 'my super name',
206 category: 5, 240 category: 5,
241 licence: 1,
207 description: 'my super description', 242 description: 'my super description',
208 tags: [ 'tag1', 't' ] 243 tags: [ 'tag1', 't' ]
209 } 244 }
@@ -217,6 +252,7 @@ describe('Test videos API validator', function () {
217 const data = { 252 const data = {
218 name: 'my super name', 253 name: 'my super name',
219 category: 5, 254 category: 5,
255 licence: 1,
220 description: 'my super description', 256 description: 'my super description',
221 tags: [ 'mysupertagtoolong', 'tag1' ] 257 tags: [ 'mysupertagtoolong', 'tag1' ]
222 } 258 }
@@ -230,6 +266,7 @@ describe('Test videos API validator', function () {
230 const data = { 266 const data = {
231 name: 'my super name', 267 name: 'my super name',
232 category: 5, 268 category: 5,
269 licence: 1,
233 description: 'my super description', 270 description: 'my super description',
234 tags: [ 'tag1', 'tag2' ] 271 tags: [ 'tag1', 'tag2' ]
235 } 272 }
@@ -241,6 +278,7 @@ describe('Test videos API validator', function () {
241 const data = { 278 const data = {
242 name: 'my super name', 279 name: 'my super name',
243 category: 5, 280 category: 5,
281 licence: 1,
244 description: 'my super description', 282 description: 'my super description',
245 tags: [ 'tag1', 'tag2' ] 283 tags: [ 'tag1', 'tag2' ]
246 } 284 }
@@ -254,6 +292,7 @@ describe('Test videos API validator', function () {
254 const data = { 292 const data = {
255 name: 'my super name', 293 name: 'my super name',
256 category: 5, 294 category: 5,
295 licence: 1,
257 description: 'my super description', 296 description: 'my super description',
258 tags: [ 'tag1', 'tag2' ] 297 tags: [ 'tag1', 'tag2' ]
259 } 298 }
@@ -267,6 +306,7 @@ describe('Test videos API validator', function () {
267 const data = { 306 const data = {
268 name: 'my super name', 307 name: 'my super name',
269 category: 5, 308 category: 5,
309 licence: 1,
270 description: 'my super description', 310 description: 'my super description',
271 tags: [ 'tag1', 'tag2' ] 311 tags: [ 'tag1', 'tag2' ]
272 } 312 }
@@ -304,6 +344,7 @@ describe('Test videos API validator', function () {
304 it('Should fail without a valid uuid', function (done) { 344 it('Should fail without a valid uuid', function (done) {
305 const data = { 345 const data = {
306 category: 5, 346 category: 5,
347 licence: 2,
307 description: 'my super description', 348 description: 'my super description',
308 tags: [ 'tag1', 'tag2' ] 349 tags: [ 'tag1', 'tag2' ]
309 } 350 }
@@ -313,6 +354,7 @@ describe('Test videos API validator', function () {
313 it('Should fail with an unknown id', function (done) { 354 it('Should fail with an unknown id', function (done) {
314 const data = { 355 const data = {
315 category: 5, 356 category: 5,
357 licence: 2,
316 description: 'my super description', 358 description: 'my super description',
317 tags: [ 'tag1', 'tag2' ] 359 tags: [ 'tag1', 'tag2' ]
318 } 360 }
@@ -323,6 +365,7 @@ describe('Test videos API validator', function () {
323 const data = { 365 const data = {
324 name: 'My very very very very very very very very very very very very very very very very long name', 366 name: 'My very very very very very very very very very very very very very very very very long name',
325 category: 5, 367 category: 5,
368 licence: 2,
326 description: 'my super description', 369 description: 'my super description',
327 tags: [ 'tag1', 'tag2' ] 370 tags: [ 'tag1', 'tag2' ]
328 } 371 }
@@ -333,6 +376,18 @@ describe('Test videos API validator', function () {
333 const data = { 376 const data = {
334 name: 'my super name', 377 name: 'my super name',
335 category: 128, 378 category: 128,
379 licence: 2,
380 description: 'my super description',
381 tags: [ 'tag1', 'tag2' ]
382 }
383 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
384 })
385
386 it('Should fail with a bad licence', function (done) {
387 const data = {
388 name: 'my super name',
389 category: 5,
390 licence: 128,
336 description: 'my super description', 391 description: 'my super description',
337 tags: [ 'tag1', 'tag2' ] 392 tags: [ 'tag1', 'tag2' ]
338 } 393 }
@@ -343,6 +398,7 @@ describe('Test videos API validator', function () {
343 const data = { 398 const data = {
344 name: 'my super name', 399 name: 'my super name',
345 category: 5, 400 category: 5,
401 licence: 2,
346 description: 'my super description which is very very very very very very very very very very very very very very' + 402 description: 'my super description which is very very very very very very very very very very very very very very' +
347 'very very very very very very very very very very very very very very very very very very very very very' + 403 'very very very very very very very very very very very very very very very very very very very very very' +
348 'very very very very very very very very very very very very very very very long', 404 'very very very very very very very very very very very very very very very long',
@@ -355,6 +411,7 @@ describe('Test videos API validator', function () {
355 const data = { 411 const data = {
356 name: 'my super name', 412 name: 'my super name',
357 category: 5, 413 category: 5,
414 licence: 2,
358 description: 'my super description', 415 description: 'my super description',
359 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] 416 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
360 } 417 }
@@ -365,6 +422,7 @@ describe('Test videos API validator', function () {
365 const data = { 422 const data = {
366 name: 'my super name', 423 name: 'my super name',
367 category: 5, 424 category: 5,
425 licence: 2,
368 description: 'my super description', 426 description: 'my super description',
369 tags: [ 'tag1', 't' ] 427 tags: [ 'tag1', 't' ]
370 } 428 }
@@ -375,6 +433,7 @@ describe('Test videos API validator', function () {
375 const data = { 433 const data = {
376 name: 'my super name', 434 name: 'my super name',
377 category: 5, 435 category: 5,
436 licence: 2,
378 description: 'my super description', 437 description: 'my super description',
379 tags: [ 'mysupertagtoolong', 'tag1' ] 438 tags: [ 'mysupertagtoolong', 'tag1' ]
380 } 439 }
diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js
index d5c723b3b..69ef38c20 100644
--- a/server/tests/api/multiple-pods.js
+++ b/server/tests/api/multiple-pods.js
@@ -82,6 +82,8 @@ describe('Test multiple pods', function () {
82 function (next) { 82 function (next) {
83 const videoAttributes = { 83 const videoAttributes = {
84 name: 'my super name for pod 1', 84 name: 'my super name for pod 1',
85 category: 5,
86 licence: 4,
85 description: 'my super description for pod 1', 87 description: 'my super description for pod 1',
86 tags: [ 'tag1p1', 'tag2p1' ], 88 tags: [ 'tag1p1', 'tag2p1' ],
87 fixture: 'video_short1.webm' 89 fixture: 'video_short1.webm'
@@ -108,6 +110,8 @@ describe('Test multiple pods', function () {
108 expect(video.name).to.equal('my super name for pod 1') 110 expect(video.name).to.equal('my super name for pod 1')
109 expect(video.category).to.equal(5) 111 expect(video.category).to.equal(5)
110 expect(video.categoryLabel).to.equal('Sports') 112 expect(video.categoryLabel).to.equal('Sports')
113 expect(video.licence).to.equal(4)
114 expect(video.licenceLabel).to.equal('Attribution - Non Commercial')
111 expect(video.description).to.equal('my super description for pod 1') 115 expect(video.description).to.equal('my super description for pod 1')
112 expect(video.podHost).to.equal('localhost:9001') 116 expect(video.podHost).to.equal('localhost:9001')
113 expect(video.magnetUri).to.exist 117 expect(video.magnetUri).to.exist
@@ -150,6 +154,7 @@ describe('Test multiple pods', function () {
150 const videoAttributes = { 154 const videoAttributes = {
151 name: 'my super name for pod 2', 155 name: 'my super name for pod 2',
152 category: 4, 156 category: 4,
157 licence: 3,
153 description: 'my super description for pod 2', 158 description: 'my super description for pod 2',
154 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], 159 tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ],
155 fixture: 'video_short2.webm' 160 fixture: 'video_short2.webm'
@@ -176,6 +181,8 @@ describe('Test multiple pods', function () {
176 expect(video.name).to.equal('my super name for pod 2') 181 expect(video.name).to.equal('my super name for pod 2')
177 expect(video.category).to.equal(4) 182 expect(video.category).to.equal(4)
178 expect(video.categoryLabel).to.equal('Art') 183 expect(video.categoryLabel).to.equal('Art')
184 expect(video.licence).to.equal(3)
185 expect(video.licenceLabel).to.equal('Attribution - No Derivatives')
179 expect(video.description).to.equal('my super description for pod 2') 186 expect(video.description).to.equal('my super description for pod 2')
180 expect(video.podHost).to.equal('localhost:9002') 187 expect(video.podHost).to.equal('localhost:9002')
181 expect(video.magnetUri).to.exist 188 expect(video.magnetUri).to.exist
@@ -218,6 +225,7 @@ describe('Test multiple pods', function () {
218 const videoAttributes = { 225 const videoAttributes = {
219 name: 'my super name for pod 3', 226 name: 'my super name for pod 3',
220 category: 6, 227 category: 6,
228 licence: 5,
221 description: 'my super description for pod 3', 229 description: 'my super description for pod 3',
222 tags: [ 'tag1p3' ], 230 tags: [ 'tag1p3' ],
223 fixture: 'video_short3.webm' 231 fixture: 'video_short3.webm'
@@ -228,6 +236,7 @@ describe('Test multiple pods', function () {
228 const videoAttributes = { 236 const videoAttributes = {
229 name: 'my super name for pod 3-2', 237 name: 'my super name for pod 3-2',
230 category: 7, 238 category: 7,
239 licence: 6,
231 description: 'my super description for pod 3-2', 240 description: 'my super description for pod 3-2',
232 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], 241 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
233 fixture: 'video_short.webm' 242 fixture: 'video_short.webm'
@@ -264,6 +273,8 @@ describe('Test multiple pods', function () {
264 expect(video1.name).to.equal('my super name for pod 3') 273 expect(video1.name).to.equal('my super name for pod 3')
265 expect(video1.category).to.equal(6) 274 expect(video1.category).to.equal(6)
266 expect(video1.categoryLabel).to.equal('Travels') 275 expect(video1.categoryLabel).to.equal('Travels')
276 expect(video1.licence).to.equal(5)
277 expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike')
267 expect(video1.description).to.equal('my super description for pod 3') 278 expect(video1.description).to.equal('my super description for pod 3')
268 expect(video1.podHost).to.equal('localhost:9003') 279 expect(video1.podHost).to.equal('localhost:9003')
269 expect(video1.magnetUri).to.exist 280 expect(video1.magnetUri).to.exist
@@ -276,6 +287,8 @@ describe('Test multiple pods', function () {
276 expect(video2.name).to.equal('my super name for pod 3-2') 287 expect(video2.name).to.equal('my super name for pod 3-2')
277 expect(video2.category).to.equal(7) 288 expect(video2.category).to.equal(7)
278 expect(video2.categoryLabel).to.equal('Gaming') 289 expect(video2.categoryLabel).to.equal('Gaming')
290 expect(video2.licence).to.equal(6)
291 expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
279 expect(video2.description).to.equal('my super description for pod 3-2') 292 expect(video2.description).to.equal('my super description for pod 3-2')
280 expect(video2.podHost).to.equal('localhost:9003') 293 expect(video2.podHost).to.equal('localhost:9003')
281 expect(video2.magnetUri).to.exist 294 expect(video2.magnetUri).to.exist
@@ -624,6 +637,7 @@ describe('Test multiple pods', function () {
624 const attributes = { 637 const attributes = {
625 name: 'my super video updated', 638 name: 'my super video updated',
626 category: 10, 639 category: 10,
640 licence: 7,
627 description: 'my super description updated', 641 description: 'my super description updated',
628 tags: [ 'tagup1', 'tagup2' ] 642 tags: [ 'tagup1', 'tagup2' ]
629 } 643 }
@@ -652,6 +666,8 @@ describe('Test multiple pods', function () {
652 expect(!!videoUpdated).to.be.true 666 expect(!!videoUpdated).to.be.true
653 expect(videoUpdated.category).to.equal(10) 667 expect(videoUpdated.category).to.equal(10)
654 expect(videoUpdated.categoryLabel).to.equal('Entertainment') 668 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
669 expect(videoUpdated.licence).to.equal(7)
670 expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication')
655 expect(videoUpdated.description).to.equal('my super description updated') 671 expect(videoUpdated.description).to.equal('my super description updated')
656 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) 672 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
657 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true 673 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js
index 9465f6034..6d7ebdc9b 100644
--- a/server/tests/api/single-pod.js
+++ b/server/tests/api/single-pod.js
@@ -57,6 +57,19 @@ describe('Test a single pod', function () {
57 }) 57 })
58 }) 58 })
59 59
60 it('Should list video licences', function (done) {
61 videosUtils.getVideoLicences(server.url, function (err, res) {
62 if (err) throw err
63
64 const licences = res.body
65 expect(Object.keys(licences)).to.have.length.above(5)
66
67 expect(licences[3]).to.equal('Attribution - No Derivatives')
68
69 done()
70 })
71 })
72
60 it('Should not have videos', function (done) { 73 it('Should not have videos', function (done) {
61 videosUtils.getVideosList(server.url, function (err, res) { 74 videosUtils.getVideosList(server.url, function (err, res) {
62 if (err) throw err 75 if (err) throw err
@@ -73,6 +86,7 @@ describe('Test a single pod', function () {
73 const videoAttributes = { 86 const videoAttributes = {
74 name: 'my super name', 87 name: 'my super name',
75 category: 2, 88 category: 2,
89 licence: 6,
76 tags: [ 'tag1', 'tag2', 'tag3' ] 90 tags: [ 'tag1', 'tag2', 'tag3' ]
77 } 91 }
78 videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, done) 92 videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, done)
@@ -93,6 +107,8 @@ describe('Test a single pod', function () {
93 expect(video.name).to.equal('my super name') 107 expect(video.name).to.equal('my super name')
94 expect(video.category).to.equal(2) 108 expect(video.category).to.equal(2)
95 expect(video.categoryLabel).to.equal('Films') 109 expect(video.categoryLabel).to.equal('Films')
110 expect(video.licence).to.equal(6)
111 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
96 expect(video.description).to.equal('my super description') 112 expect(video.description).to.equal('my super description')
97 expect(video.podHost).to.equal('localhost:9001') 113 expect(video.podHost).to.equal('localhost:9001')
98 expect(video.magnetUri).to.exist 114 expect(video.magnetUri).to.exist
@@ -130,6 +146,8 @@ describe('Test a single pod', function () {
130 expect(video.name).to.equal('my super name') 146 expect(video.name).to.equal('my super name')
131 expect(video.category).to.equal(2) 147 expect(video.category).to.equal(2)
132 expect(video.categoryLabel).to.equal('Films') 148 expect(video.categoryLabel).to.equal('Films')
149 expect(video.licence).to.equal(6)
150 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
133 expect(video.description).to.equal('my super description') 151 expect(video.description).to.equal('my super description')
134 expect(video.podHost).to.equal('localhost:9001') 152 expect(video.podHost).to.equal('localhost:9001')
135 expect(video.magnetUri).to.exist 153 expect(video.magnetUri).to.exist
@@ -171,6 +189,8 @@ describe('Test a single pod', function () {
171 expect(video.name).to.equal('my super name') 189 expect(video.name).to.equal('my super name')
172 expect(video.category).to.equal(2) 190 expect(video.category).to.equal(2)
173 expect(video.categoryLabel).to.equal('Films') 191 expect(video.categoryLabel).to.equal('Films')
192 expect(video.licence).to.equal(6)
193 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
174 expect(video.description).to.equal('my super description') 194 expect(video.description).to.equal('my super description')
175 expect(video.podHost).to.equal('localhost:9001') 195 expect(video.podHost).to.equal('localhost:9001')
176 expect(video.author).to.equal('root') 196 expect(video.author).to.equal('root')
@@ -228,6 +248,8 @@ describe('Test a single pod', function () {
228 expect(video.name).to.equal('my super name') 248 expect(video.name).to.equal('my super name')
229 expect(video.category).to.equal(2) 249 expect(video.category).to.equal(2)
230 expect(video.categoryLabel).to.equal('Films') 250 expect(video.categoryLabel).to.equal('Films')
251 expect(video.licence).to.equal(6)
252 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
231 expect(video.description).to.equal('my super description') 253 expect(video.description).to.equal('my super description')
232 expect(video.podHost).to.equal('localhost:9001') 254 expect(video.podHost).to.equal('localhost:9001')
233 expect(video.author).to.equal('root') 255 expect(video.author).to.equal('root')
@@ -324,6 +346,7 @@ describe('Test a single pod', function () {
324 name: video + ' name', 346 name: video + ' name',
325 description: video + ' description', 347 description: video + ' description',
326 category: 2, 348 category: 2,
349 licence: 1,
327 tags: [ 'tag1', 'tag2', 'tag3' ], 350 tags: [ 'tag1', 'tag2', 'tag3' ],
328 fixture: video 351 fixture: video
329 } 352 }
@@ -548,6 +571,7 @@ describe('Test a single pod', function () {
548 const attributes = { 571 const attributes = {
549 name: 'my super video updated', 572 name: 'my super video updated',
550 category: 4, 573 category: 4,
574 licence: 2,
551 description: 'my super description updated', 575 description: 'my super description updated',
552 tags: [ 'tagup1', 'tagup2' ] 576 tags: [ 'tagup1', 'tagup2' ]
553 } 577 }
@@ -565,6 +589,8 @@ describe('Test a single pod', function () {
565 expect(video.name).to.equal('my super video updated') 589 expect(video.name).to.equal('my super video updated')
566 expect(video.category).to.equal(4) 590 expect(video.category).to.equal(4)
567 expect(video.categoryLabel).to.equal('Art') 591 expect(video.categoryLabel).to.equal('Art')
592 expect(video.licence).to.equal(2)
593 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
568 expect(video.description).to.equal('my super description updated') 594 expect(video.description).to.equal('my super description updated')
569 expect(video.podHost).to.equal('localhost:9001') 595 expect(video.podHost).to.equal('localhost:9001')
570 expect(video.author).to.equal('root') 596 expect(video.author).to.equal('root')
@@ -604,6 +630,8 @@ describe('Test a single pod', function () {
604 expect(video.name).to.equal('my super video updated') 630 expect(video.name).to.equal('my super video updated')
605 expect(video.category).to.equal(4) 631 expect(video.category).to.equal(4)
606 expect(video.categoryLabel).to.equal('Art') 632 expect(video.categoryLabel).to.equal('Art')
633 expect(video.licence).to.equal(2)
634 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
607 expect(video.description).to.equal('my super description updated') 635 expect(video.description).to.equal('my super description updated')
608 expect(video.podHost).to.equal('localhost:9001') 636 expect(video.podHost).to.equal('localhost:9001')
609 expect(video.author).to.equal('root') 637 expect(video.author).to.equal('root')
@@ -633,6 +661,8 @@ describe('Test a single pod', function () {
633 expect(video.name).to.equal('my super video updated') 661 expect(video.name).to.equal('my super video updated')
634 expect(video.category).to.equal(4) 662 expect(video.category).to.equal(4)
635 expect(video.categoryLabel).to.equal('Art') 663 expect(video.categoryLabel).to.equal('Art')
664 expect(video.licence).to.equal(2)
665 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
636 expect(video.description).to.equal('hello everybody') 666 expect(video.description).to.equal('hello everybody')
637 expect(video.podHost).to.equal('localhost:9001') 667 expect(video.podHost).to.equal('localhost:9001')
638 expect(video.author).to.equal('root') 668 expect(video.author).to.equal('root')
diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js
index 32afeec68..7777768c8 100644
--- a/server/tests/real-world/real-world.js
+++ b/server/tests/real-world/real-world.js
@@ -205,6 +205,7 @@ function upload (servers, numServer, callback) {
205 const videoAttributes = { 205 const videoAttributes = {
206 name: Date.now() + ' name', 206 name: Date.now() + ' name',
207 category: 4, 207 category: 4,
208 licence: 2,
208 description: Date.now() + ' description', 209 description: Date.now() + ' description',
209 tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ], 210 tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ],
210 fixture: 'video_short1.webm' 211 fixture: 'video_short1.webm'
diff --git a/server/tests/real-world/tools/upload.js b/server/tests/real-world/tools/upload.js
index 856251c7f..7b97ebf0b 100644
--- a/server/tests/real-world/tools/upload.js
+++ b/server/tests/real-world/tools/upload.js
@@ -9,7 +9,8 @@ program
9 .option('-u, --url <url>', 'Server url') 9 .option('-u, --url <url>', 'Server url')
10 .option('-a, --access-token <token>', 'Access token') 10 .option('-a, --access-token <token>', 'Access token')
11 .option('-n, --name <name>', 'Video name') 11 .option('-n, --name <name>', 'Video name')
12 .option('-d, --category <category number>', 'Category number') 12 .option('-c, --category <category number>', 'Category number')
13 .option('-l, --licence <licence number>', 'Licence number')
13 .option('-d, --description <description>', 'Video description') 14 .option('-d, --description <description>', 'Video description')
14 .option('-t, --tags <tags>', 'Video tags', list) 15 .option('-t, --tags <tags>', 'Video tags', list)
15 .option('-f, --file <file>', 'Video absolute file path') 16 .option('-f, --file <file>', 'Video absolute file path')
@@ -20,6 +21,7 @@ if (
20 !program.accessToken || 21 !program.accessToken ||
21 !program.name || 22 !program.name ||
22 !program.category || 23 !program.category ||
24 !program.licence ||
23 !program.description || 25 !program.description ||
24 !program.tags || 26 !program.tags ||
25 !Array.isArray(program.tags) || 27 !Array.isArray(program.tags) ||
@@ -37,6 +39,7 @@ fs.access(program.file, fs.F_OK, function (err) {
37 program.accessToken, 39 program.accessToken,
38 program.name, 40 program.name,
39 program.category, 41 program.category,
42 program.licence,
40 program.description, 43 program.description,
41 program.tags, 44 program.tags,
42 program.file 45 program.file
@@ -49,12 +52,13 @@ function list (val) {
49 return val.split(',') 52 return val.split(',')
50} 53}
51 54
52function upload (url, accessToken, name, category, description, tags, fixture) { 55function upload (url, accessToken, name, category, licence, description, tags, fixture) {
53 console.log('Uploading %s video...', program.name) 56 console.log('Uploading %s video...', program.name)
54 57
55 const videoAttributes = { 58 const videoAttributes = {
56 name, 59 name,
57 category, 60 category,
61 licence,
58 description, 62 description,
59 tags, 63 tags,
60 fixture 64 fixture
diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js
index ad0d74076..d1e0b7b14 100644
--- a/server/tests/utils/videos.js
+++ b/server/tests/utils/videos.js
@@ -6,6 +6,7 @@ const request = require('supertest')
6 6
7const videosUtils = { 7const videosUtils = {
8 getVideoCategories, 8 getVideoCategories,
9 getVideoLicences,
9 getAllVideosListBy, 10 getAllVideosListBy,
10 getVideo, 11 getVideo,
11 getVideosList, 12 getVideosList,
@@ -34,6 +35,17 @@ function getVideoCategories (url, end) {
34 .end(end) 35 .end(end)
35} 36}
36 37
38function getVideoLicences (url, end) {
39 const path = '/api/v1/videos/licences'
40
41 request(url)
42 .get(path)
43 .set('Accept', 'application/json')
44 .expect(200)
45 .expect('Content-Type', /json/)
46 .end(end)
47}
48
37function getAllVideosListBy (url, end) { 49function getAllVideosListBy (url, end) {
38 const path = '/api/v1/videos' 50 const path = '/api/v1/videos'
39 51
@@ -205,6 +217,7 @@ function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end)
205 let attributes = { 217 let attributes = {
206 name: 'my super video', 218 name: 'my super video',
207 category: 5, 219 category: 5,
220 licence: 4,
208 description: 'my super description', 221 description: 'my super description',
209 tags: [ 'tag' ], 222 tags: [ 'tag' ],
210 fixture: 'video_short.webm' 223 fixture: 'video_short.webm'
@@ -217,6 +230,7 @@ function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end)
217 .set('Authorization', 'Bearer ' + accessToken) 230 .set('Authorization', 'Bearer ' + accessToken)
218 .field('name', attributes.name) 231 .field('name', attributes.name)
219 .field('category', attributes.category) 232 .field('category', attributes.category)
233 .field('licence', attributes.licence)
220 .field('description', attributes.description) 234 .field('description', attributes.description)
221 235
222 for (let i = 0; i < attributes.tags.length; i++) { 236 for (let i = 0; i < attributes.tags.length; i++) {
@@ -250,6 +264,7 @@ function updateVideo (url, accessToken, id, attributes, specialStatus, end) {
250 264
251 if (attributes.name) req.field('name', attributes.name) 265 if (attributes.name) req.field('name', attributes.name)
252 if (attributes.category) req.field('category', attributes.category) 266 if (attributes.category) req.field('category', attributes.category)
267 if (attributes.licence) req.field('licence', attributes.licence)
253 if (attributes.description) req.field('description', attributes.description) 268 if (attributes.description) req.field('description', attributes.description)
254 269
255 if (attributes.tags) { 270 if (attributes.tags) {