aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/pods.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-11-14 20:03:04 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-11-16 20:29:26 +0100
commit49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed (patch)
tree68c59d67637a297d513e07ea96ba236a7f0cd43b /server/models/pods.js
parent41b5da1d8cb41f5c49f0e0a01a54106c9a5925dd (diff)
downloadPeerTube-49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed.tar.gz
PeerTube-49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed.tar.zst
PeerTube-49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed.zip
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).
Diffstat (limited to 'server/models/pods.js')
-rw-r--r--server/models/pods.js17
1 files changed, 8 insertions, 9 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) {