aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video.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/video.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/video.js')
-rw-r--r--server/models/video.js32
1 files changed, 13 insertions, 19 deletions
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) {