aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/pods.js17
-rw-r--r--server/models/request.js2
-rw-r--r--server/models/video.js32
3 files changed, 22 insertions, 29 deletions
diff --git a/server/models/pods.js b/server/models/pods.js
index 6ab018c1c..49c73472a 100644
--- a/server/models/pods.js
+++ b/server/models/pods.js
@@ -12,7 +12,7 @@ const Video = mongoose.model('Video')
12// --------------------------------------------------------------------------- 12// ---------------------------------------------------------------------------
13 13
14const PodSchema = mongoose.Schema({ 14const PodSchema = mongoose.Schema({
15 url: String, 15 host: String,
16 publicKey: String, 16 publicKey: String,
17 score: { type: Number, max: constants.FRIEND_SCORE.MAX }, 17 score: { type: Number, max: constants.FRIEND_SCORE.MAX },
18 createdDate: { 18 createdDate: {
@@ -21,8 +21,7 @@ const PodSchema = mongoose.Schema({
21 } 21 }
22}) 22})
23 23
24// TODO: set options (TLD...) 24PodSchema.path('host').validate(validator.isURL)
25PodSchema.path('url').validate(validator.isURL)
26PodSchema.path('publicKey').required(true) 25PodSchema.path('publicKey').required(true)
27PodSchema.path('score').validate(function (value) { return !isNaN(value) }) 26PodSchema.path('score').validate(function (value) { return !isNaN(value) })
28 27
@@ -37,14 +36,14 @@ PodSchema.statics = {
37 listAllIds, 36 listAllIds,
38 listBadPods, 37 listBadPods,
39 load, 38 load,
40 loadByUrl, 39 loadByHost,
41 removeAll 40 removeAll
42} 41}
43 42
44PodSchema.pre('save', function (next) { 43PodSchema.pre('save', function (next) {
45 const self = this 44 const self = this
46 45
47 Pod.loadByUrl(this.url, function (err, pod) { 46 Pod.loadByHost(this.host, function (err, pod) {
48 if (err) return next(err) 47 if (err) return next(err)
49 48
50 if (pod) return next(new Error('Pod already exists.')) 49 if (pod) return next(new Error('Pod already exists.'))
@@ -56,7 +55,7 @@ PodSchema.pre('save', function (next) {
56 55
57PodSchema.pre('remove', function (next) { 56PodSchema.pre('remove', function (next) {
58 // Remove the videos owned by this pod too 57 // Remove the videos owned by this pod too
59 Video.listByUrl(this.url, function (err, videos) { 58 Video.listByHost(this.host, function (err, videos) {
60 if (err) return next(err) 59 if (err) return next(err)
61 60
62 each(videos, function (video, callbackEach) { 61 each(videos, function (video, callbackEach) {
@@ -72,7 +71,7 @@ const Pod = mongoose.model('Pod', PodSchema)
72function toFormatedJSON () { 71function toFormatedJSON () {
73 const json = { 72 const json = {
74 id: this._id, 73 id: this._id,
75 url: this.url, 74 host: this.host,
76 score: this.score, 75 score: this.score,
77 createdDate: this.createdDate 76 createdDate: this.createdDate
78 } 77 }
@@ -111,8 +110,8 @@ function load (id, callback) {
111 return this.findById(id, callback) 110 return this.findById(id, callback)
112} 111}
113 112
114function loadByUrl (url, callback) { 113function loadByHost (host, callback) {
115 return this.findOne({ url: url }, callback) 114 return this.findOne({ host }, callback)
116} 115}
117 116
118function removeAll (callback) { 117function removeAll (callback) {
diff --git a/server/models/request.js b/server/models/request.js
index f5eec2134..59bf440fe 100644
--- a/server/models/request.js
+++ b/server/models/request.js
@@ -121,7 +121,7 @@ function makeRequest (toPod, requestEndpoint, requestsToMake, callback) {
121 if (err || (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 204)) { 121 if (err || (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 204)) {
122 logger.error( 122 logger.error(
123 'Error sending secure request to %s pod.', 123 'Error sending secure request to %s pod.',
124 toPod.url, 124 toPod.host,
125 { 125 {
126 error: err || new Error('Status code not 20x : ' + res.statusCode) 126 error: err || new Error('Status code not 20x : ' + res.statusCode)
127 } 127 }
diff --git a/server/models/video.js b/server/models/video.js
index 0da2cb8ab..6d3fa3fb8 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -28,10 +28,9 @@ const VideoSchema = mongoose.Schema({
28 magnet: { 28 magnet: {
29 infoHash: String 29 infoHash: String
30 }, 30 },
31 podUrl: String, 31 podHost: String,
32 author: String, 32 author: String,
33 duration: Number, 33 duration: Number,
34 thumbnail: String,
35 tags: [ String ], 34 tags: [ String ],
36 createdDate: { 35 createdDate: {
37 type: Date, 36 type: Date,
@@ -41,14 +40,9 @@ const VideoSchema = mongoose.Schema({
41 40
42VideoSchema.path('name').validate(customVideosValidators.isVideoNameValid) 41VideoSchema.path('name').validate(customVideosValidators.isVideoNameValid)
43VideoSchema.path('description').validate(customVideosValidators.isVideoDescriptionValid) 42VideoSchema.path('description').validate(customVideosValidators.isVideoDescriptionValid)
44VideoSchema.path('podUrl').validate(customVideosValidators.isVideoPodUrlValid) 43VideoSchema.path('podHost').validate(customVideosValidators.isVideoPodHostValid)
45VideoSchema.path('author').validate(customVideosValidators.isVideoAuthorValid) 44VideoSchema.path('author').validate(customVideosValidators.isVideoAuthorValid)
46VideoSchema.path('duration').validate(customVideosValidators.isVideoDurationValid) 45VideoSchema.path('duration').validate(customVideosValidators.isVideoDurationValid)
47// The tumbnail can be the path or the data in base 64
48// The pre save hook will convert the base 64 data in a file on disk and replace the thumbnail key by the filename
49VideoSchema.path('thumbnail').validate(function (value) {
50 return customVideosValidators.isVideoThumbnailValid(value) || customVideosValidators.isVideoThumbnail64Valid(value)
51})
52VideoSchema.path('tags').validate(customVideosValidators.isVideoTagsValid) 46VideoSchema.path('tags').validate(customVideosValidators.isVideoTagsValid)
53 47
54VideoSchema.methods = { 48VideoSchema.methods = {
@@ -65,8 +59,8 @@ VideoSchema.methods = {
65VideoSchema.statics = { 59VideoSchema.statics = {
66 getDurationFromFile, 60 getDurationFromFile,
67 listForApi, 61 listForApi,
68 listByUrlAndRemoteId, 62 listByHostAndRemoteId,
69 listByUrl, 63 listByHost,
70 listOwned, 64 listOwned,
71 listOwnedByAuthor, 65 listOwnedByAuthor,
72 listRemotes, 66 listRemotes,
@@ -107,7 +101,7 @@ VideoSchema.pre('save', function (next) {
107 101
108 if (video.isOwned()) { 102 if (video.isOwned()) {
109 const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename()) 103 const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename())
110 this.podUrl = constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT 104 this.podHost = constants.CONFIG.WEBSERVER.HOST
111 105
112 tasks.push( 106 tasks.push(
113 // TODO: refractoring 107 // TODO: refractoring
@@ -160,8 +154,8 @@ function generateMagnetUri () {
160 baseUrlHttp = constants.CONFIG.WEBSERVER.URL 154 baseUrlHttp = constants.CONFIG.WEBSERVER.URL
161 baseUrlWs = constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT 155 baseUrlWs = constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT
162 } else { 156 } else {
163 baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.podUrl 157 baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.podHost
164 baseUrlWs = constants.REMOTE_SCHEME.WS + this.podUrl 158 baseUrlWs = constants.REMOTE_SCHEME.WS + this.podHost
165 } 159 }
166 160
167 const xs = baseUrlHttp + constants.STATIC_PATHS.TORRENTS + this.getTorrentName() 161 const xs = baseUrlHttp + constants.STATIC_PATHS.TORRENTS + this.getTorrentName()
@@ -215,7 +209,7 @@ function toFormatedJSON () {
215 id: this._id, 209 id: this._id,
216 name: this.name, 210 name: this.name,
217 description: this.description, 211 description: this.description,
218 podUrl: this.podUrl, 212 podHost: this.podHost,
219 isLocal: this.isOwned(), 213 isLocal: this.isOwned(),
220 magnetUri: this.generateMagnetUri(), 214 magnetUri: this.generateMagnetUri(),
221 author: this.author, 215 author: this.author,
@@ -249,7 +243,7 @@ function toRemoteJSON (callback) {
249 thumbnailBase64: new Buffer(thumbnailData).toString('base64'), 243 thumbnailBase64: new Buffer(thumbnailData).toString('base64'),
250 tags: self.tags, 244 tags: self.tags,
251 createdDate: self.createdDate, 245 createdDate: self.createdDate,
252 podUrl: self.podUrl 246 podHost: self.podHost
253 } 247 }
254 248
255 return callback(null, remoteVideo) 249 return callback(null, remoteVideo)
@@ -271,12 +265,12 @@ function listForApi (start, count, sort, callback) {
271 return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback) 265 return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback)
272} 266}
273 267
274function listByUrlAndRemoteId (fromUrl, remoteId, callback) { 268function listByHostAndRemoteId (fromHost, remoteId, callback) {
275 this.find({ podUrl: fromUrl, remoteId: remoteId }, callback) 269 this.find({ podHost: fromHost, remoteId: remoteId }, callback)
276} 270}
277 271
278function listByUrl (fromUrl, callback) { 272function listByHost (fromHost, callback) {
279 this.find({ podUrl: fromUrl }, callback) 273 this.find({ podHost: fromHost }, callback)
280} 274}
281 275
282function listOwned (callback) { 276function listOwned (callback) {