diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-03-22 21:15:55 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-03-22 21:25:24 +0100 |
commit | 6e07c3de88791a0b342e0cc319590048117f9c2d (patch) | |
tree | 049f88d3f6d3ec0aeea09702a583deb86d6ef78f /server/models | |
parent | 2d7653dc8726185615bab66353c4e3fb8fbb5a5f (diff) | |
download | PeerTube-6e07c3de88791a0b342e0cc319590048117f9c2d.tar.gz PeerTube-6e07c3de88791a0b342e0cc319590048117f9c2d.tar.zst PeerTube-6e07c3de88791a0b342e0cc319590048117f9c2d.zip |
Add video category support
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/server/models/video.js b/server/models/video.js index 182555c85..c4c7b5de8 100644 --- a/server/models/video.js +++ b/server/models/video.js | |||
@@ -51,6 +51,16 @@ module.exports = function (sequelize, DataTypes) { | |||
51 | isUUID: 4 | 51 | isUUID: 4 |
52 | } | 52 | } |
53 | }, | 53 | }, |
54 | category: { | ||
55 | type: DataTypes.INTEGER, | ||
56 | allowNull: false, | ||
57 | validate: { | ||
58 | categoryValid: function (value) { | ||
59 | const res = customVideosValidators.isVideoCategoryValid(value) | ||
60 | if (res === false) throw new Error('Video category is not valid.') | ||
61 | } | ||
62 | } | ||
63 | }, | ||
54 | description: { | 64 | description: { |
55 | type: DataTypes.STRING, | 65 | type: DataTypes.STRING, |
56 | allowNull: false, | 66 | allowNull: false, |
@@ -360,9 +370,15 @@ function toFormatedJSON () { | |||
360 | podHost = constants.CONFIG.WEBSERVER.HOST | 370 | podHost = constants.CONFIG.WEBSERVER.HOST |
361 | } | 371 | } |
362 | 372 | ||
373 | // Maybe our pod is not up to date and there are new categories since our version | ||
374 | let categoryLabel = constants.VIDEO_CATEGORIES[this.category] | ||
375 | if (!categoryLabel) categoryLabel = 'Misc' | ||
376 | |||
363 | const json = { | 377 | const json = { |
364 | id: this.id, | 378 | id: this.id, |
365 | name: this.name, | 379 | name: this.name, |
380 | category: this.category, | ||
381 | categoryLabel, | ||
366 | description: this.description, | 382 | description: this.description, |
367 | podHost, | 383 | podHost, |
368 | isLocal: this.isOwned(), | 384 | isLocal: this.isOwned(), |
@@ -394,6 +410,7 @@ function toAddRemoteJSON (callback) { | |||
394 | 410 | ||
395 | const remoteVideo = { | 411 | const remoteVideo = { |
396 | name: self.name, | 412 | name: self.name, |
413 | category: self.category, | ||
397 | description: self.description, | 414 | description: self.description, |
398 | infoHash: self.infoHash, | 415 | infoHash: self.infoHash, |
399 | remoteId: self.id, | 416 | remoteId: self.id, |
@@ -416,6 +433,7 @@ function toAddRemoteJSON (callback) { | |||
416 | function toUpdateRemoteJSON (callback) { | 433 | function toUpdateRemoteJSON (callback) { |
417 | const json = { | 434 | const json = { |
418 | name: this.name, | 435 | name: this.name, |
436 | category: this.category, | ||
419 | description: this.description, | 437 | description: this.description, |
420 | infoHash: this.infoHash, | 438 | infoHash: this.infoHash, |
421 | remoteId: this.id, | 439 | remoteId: this.id, |