From 49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Nov 2016 20:03:04 +0100 Subject: Pod URL -> pod host. HTTPS is required to make friends. Reason: in a network with mix http/https pods, https pods won't be able to play videos from http pod (insecure requests). --- server/models/pods.js | 17 ++++++++--------- server/models/request.js | 2 +- server/models/video.js | 32 +++++++++++++------------------- 3 files changed, 22 insertions(+), 29 deletions(-) (limited to 'server/models') 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') // --------------------------------------------------------------------------- const PodSchema = mongoose.Schema({ - url: String, + host: String, publicKey: String, score: { type: Number, max: constants.FRIEND_SCORE.MAX }, createdDate: { @@ -21,8 +21,7 @@ const PodSchema = mongoose.Schema({ } }) -// TODO: set options (TLD...) -PodSchema.path('url').validate(validator.isURL) +PodSchema.path('host').validate(validator.isURL) PodSchema.path('publicKey').required(true) PodSchema.path('score').validate(function (value) { return !isNaN(value) }) @@ -37,14 +36,14 @@ PodSchema.statics = { listAllIds, listBadPods, load, - loadByUrl, + loadByHost, removeAll } PodSchema.pre('save', function (next) { const self = this - Pod.loadByUrl(this.url, function (err, pod) { + Pod.loadByHost(this.host, function (err, pod) { if (err) return next(err) if (pod) return next(new Error('Pod already exists.')) @@ -56,7 +55,7 @@ PodSchema.pre('save', function (next) { PodSchema.pre('remove', function (next) { // Remove the videos owned by this pod too - Video.listByUrl(this.url, function (err, videos) { + Video.listByHost(this.host, function (err, videos) { if (err) return next(err) each(videos, function (video, callbackEach) { @@ -72,7 +71,7 @@ const Pod = mongoose.model('Pod', PodSchema) function toFormatedJSON () { const json = { id: this._id, - url: this.url, + host: this.host, score: this.score, createdDate: this.createdDate } @@ -111,8 +110,8 @@ function load (id, callback) { return this.findById(id, callback) } -function loadByUrl (url, callback) { - return this.findOne({ url: url }, callback) +function loadByHost (host, callback) { + return this.findOne({ host }, callback) } function 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) { if (err || (res.statusCode !== 200 && res.statusCode !== 201 && res.statusCode !== 204)) { logger.error( 'Error sending secure request to %s pod.', - toPod.url, + toPod.host, { error: err || new Error('Status code not 20x : ' + res.statusCode) } 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({ magnet: { infoHash: String }, - podUrl: String, + podHost: String, author: String, duration: Number, - thumbnail: String, tags: [ String ], createdDate: { type: Date, @@ -41,14 +40,9 @@ const VideoSchema = mongoose.Schema({ VideoSchema.path('name').validate(customVideosValidators.isVideoNameValid) VideoSchema.path('description').validate(customVideosValidators.isVideoDescriptionValid) -VideoSchema.path('podUrl').validate(customVideosValidators.isVideoPodUrlValid) +VideoSchema.path('podHost').validate(customVideosValidators.isVideoPodHostValid) VideoSchema.path('author').validate(customVideosValidators.isVideoAuthorValid) VideoSchema.path('duration').validate(customVideosValidators.isVideoDurationValid) -// The tumbnail can be the path or the data in base 64 -// The pre save hook will convert the base 64 data in a file on disk and replace the thumbnail key by the filename -VideoSchema.path('thumbnail').validate(function (value) { - return customVideosValidators.isVideoThumbnailValid(value) || customVideosValidators.isVideoThumbnail64Valid(value) -}) VideoSchema.path('tags').validate(customVideosValidators.isVideoTagsValid) VideoSchema.methods = { @@ -65,8 +59,8 @@ VideoSchema.methods = { VideoSchema.statics = { getDurationFromFile, listForApi, - listByUrlAndRemoteId, - listByUrl, + listByHostAndRemoteId, + listByHost, listOwned, listOwnedByAuthor, listRemotes, @@ -107,7 +101,7 @@ VideoSchema.pre('save', function (next) { if (video.isOwned()) { const videoPath = pathUtils.join(constants.CONFIG.STORAGE.VIDEOS_DIR, video.getVideoFilename()) - this.podUrl = constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT + this.podHost = constants.CONFIG.WEBSERVER.HOST tasks.push( // TODO: refractoring @@ -160,8 +154,8 @@ function generateMagnetUri () { baseUrlHttp = constants.CONFIG.WEBSERVER.URL baseUrlWs = constants.CONFIG.WEBSERVER.WS + '://' + constants.CONFIG.WEBSERVER.HOSTNAME + ':' + constants.CONFIG.WEBSERVER.PORT } else { - baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.podUrl - baseUrlWs = constants.REMOTE_SCHEME.WS + this.podUrl + baseUrlHttp = constants.REMOTE_SCHEME.HTTP + '://' + this.podHost + baseUrlWs = constants.REMOTE_SCHEME.WS + this.podHost } const xs = baseUrlHttp + constants.STATIC_PATHS.TORRENTS + this.getTorrentName() @@ -215,7 +209,7 @@ function toFormatedJSON () { id: this._id, name: this.name, description: this.description, - podUrl: this.podUrl, + podHost: this.podHost, isLocal: this.isOwned(), magnetUri: this.generateMagnetUri(), author: this.author, @@ -249,7 +243,7 @@ function toRemoteJSON (callback) { thumbnailBase64: new Buffer(thumbnailData).toString('base64'), tags: self.tags, createdDate: self.createdDate, - podUrl: self.podUrl + podHost: self.podHost } return callback(null, remoteVideo) @@ -271,12 +265,12 @@ function listForApi (start, count, sort, callback) { return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback) } -function listByUrlAndRemoteId (fromUrl, remoteId, callback) { - this.find({ podUrl: fromUrl, remoteId: remoteId }, callback) +function listByHostAndRemoteId (fromHost, remoteId, callback) { + this.find({ podHost: fromHost, remoteId: remoteId }, callback) } -function listByUrl (fromUrl, callback) { - this.find({ podUrl: fromUrl }, callback) +function listByHost (fromHost, callback) { + this.find({ podHost: fromHost }, callback) } function listOwned (callback) { -- cgit v1.2.3