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 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'server/models/pods.js') 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) { -- cgit v1.2.3