diff options
-rw-r--r-- | public/javascripts/index.js | 10 | ||||
-rw-r--r-- | routes/api/v1/index.js (renamed from routes/api/index.js) | 0 | ||||
-rw-r--r-- | routes/api/v1/pods.js (renamed from routes/api/pods.js) | 4 | ||||
-rw-r--r-- | routes/api/v1/remoteVideos.js (renamed from routes/api/remoteVideos.js) | 4 | ||||
-rw-r--r-- | routes/api/v1/videos.js (renamed from routes/api/videos.js) | 4 | ||||
-rw-r--r-- | server.js | 12 | ||||
-rw-r--r-- | src/pods.js | 4 | ||||
-rw-r--r-- | src/videos.js | 4 | ||||
-rw-r--r-- | test/api/friends.js | 4 | ||||
-rw-r--r-- | test/api/multiplePods.js | 4 | ||||
-rw-r--r-- | test/api/singlePod.js | 11 |
11 files changed, 36 insertions, 25 deletions
diff --git a/public/javascripts/index.js b/public/javascripts/index.js index 95caf7eb4..c67e22c7b 100644 --- a/public/javascripts/index.js +++ b/public/javascripts/index.js | |||
@@ -38,7 +38,7 @@ | |||
38 | 38 | ||
39 | if (e.keyCode === 13) { | 39 | if (e.keyCode === 13) { |
40 | $.ajax({ | 40 | $.ajax({ |
41 | url: '/api/videos/search/' + search, | 41 | url: '/api/v1/videos/search/' + search, |
42 | type: 'GET', | 42 | type: 'GET', |
43 | dataType: 'json', | 43 | dataType: 'json', |
44 | success: function (videos) { | 44 | success: function (videos) { |
@@ -51,7 +51,7 @@ | |||
51 | // Join a new network | 51 | // Join a new network |
52 | function makeFriends () { | 52 | function makeFriends () { |
53 | $.ajax({ | 53 | $.ajax({ |
54 | url: '/api/pods/makefriends', | 54 | url: '/api/v1/pods/makefriends', |
55 | type: 'GET', | 55 | type: 'GET', |
56 | dataType: 'json', | 56 | dataType: 'json', |
57 | success: function () { | 57 | success: function () { |
@@ -140,7 +140,7 @@ | |||
140 | $form_video.fileupload({ | 140 | $form_video.fileupload({ |
141 | singleFileUploads: true, | 141 | singleFileUploads: true, |
142 | multipart: true, | 142 | multipart: true, |
143 | url: '/api/videos', | 143 | url: '/api/v1/videos', |
144 | autoupload: false, | 144 | autoupload: false, |
145 | add: function (e, data) { | 145 | add: function (e, data) { |
146 | var $text = $('<span></span>').addClass('name_file').text(data['files'][0]['name']) | 146 | var $text = $('<span></span>').addClass('name_file').text(data['files'][0]['name']) |
@@ -170,7 +170,7 @@ | |||
170 | // Print the list of all the videos | 170 | // Print the list of all the videos |
171 | function getVideos () { | 171 | function getVideos () { |
172 | $.ajax({ | 172 | $.ajax({ |
173 | url: '/api/videos/', | 173 | url: '/api/v1/videos/', |
174 | dataType: 'json', | 174 | dataType: 'json', |
175 | type: 'GET', | 175 | type: 'GET', |
176 | success: function (videos) { | 176 | success: function (videos) { |
@@ -181,7 +181,7 @@ | |||
181 | 181 | ||
182 | function removeVideo (video) { | 182 | function removeVideo (video) { |
183 | $.ajax({ | 183 | $.ajax({ |
184 | url: '/api/videos/' + video._id, | 184 | url: '/api/v1/videos/' + video._id, |
185 | type: 'DELETE', | 185 | type: 'DELETE', |
186 | success: function (response, status) { | 186 | success: function (response, status) { |
187 | getVideos() | 187 | getVideos() |
diff --git a/routes/api/index.js b/routes/api/v1/index.js index 9a4ec8438..9a4ec8438 100644 --- a/routes/api/index.js +++ b/routes/api/v1/index.js | |||
diff --git a/routes/api/pods.js b/routes/api/v1/pods.js index 8fa29b4f7..961388fcb 100644 --- a/routes/api/pods.js +++ b/routes/api/v1/pods.js | |||
@@ -3,8 +3,8 @@ | |||
3 | 3 | ||
4 | var express = require('express') | 4 | var express = require('express') |
5 | var router = express.Router() | 5 | var router = express.Router() |
6 | var middleware = require('../../middlewares') | 6 | var middleware = require('../../../middlewares') |
7 | var pods = require('../../src/pods') | 7 | var pods = require('../../../src/pods') |
8 | 8 | ||
9 | function listPods (req, res, next) { | 9 | function listPods (req, res, next) { |
10 | pods.list(function (err, pods_list) { | 10 | pods.list(function (err, pods_list) { |
diff --git a/routes/api/remoteVideos.js b/routes/api/v1/remoteVideos.js index 2ae3ce5bc..88b8e879b 100644 --- a/routes/api/remoteVideos.js +++ b/routes/api/v1/remoteVideos.js | |||
@@ -3,8 +3,8 @@ | |||
3 | 3 | ||
4 | var express = require('express') | 4 | var express = require('express') |
5 | var router = express.Router() | 5 | var router = express.Router() |
6 | var middleware = require('../../middlewares') | 6 | var middleware = require('../../../middlewares') |
7 | var videos = require('../../src/videos') | 7 | var videos = require('../../../src/videos') |
8 | 8 | ||
9 | function addRemoteVideos (req, res, next) { | 9 | function addRemoteVideos (req, res, next) { |
10 | videos.addRemote(req.body.data, function (err, video) { | 10 | videos.addRemote(req.body.data, function (err, video) { |
diff --git a/routes/api/videos.js b/routes/api/v1/videos.js index 087fc96bc..246620ac6 100644 --- a/routes/api/videos.js +++ b/routes/api/v1/videos.js | |||
@@ -3,8 +3,8 @@ | |||
3 | 3 | ||
4 | var express = require('express') | 4 | var express = require('express') |
5 | var router = express.Router() | 5 | var router = express.Router() |
6 | var middleware = require('../../middlewares') | 6 | var middleware = require('../../../middlewares') |
7 | var videos = require('../../src/videos') | 7 | var videos = require('../../../src/videos') |
8 | 8 | ||
9 | function listVideos (req, res, next) { | 9 | function listVideos (req, res, next) { |
10 | videos.list(function (err, videos_list) { | 10 | videos.list(function (err, videos_list) { |
@@ -1,6 +1,9 @@ | |||
1 | ;(function () { | 1 | ;(function () { |
2 | 'use strict' | 2 | 'use strict' |
3 | 3 | ||
4 | // ----------- Constantes ----------- | ||
5 | global.API_VERSION = 'v1' | ||
6 | |||
4 | // ----------- Node modules ----------- | 7 | // ----------- Node modules ----------- |
5 | var express = require('express') | 8 | var express = require('express') |
6 | var path = require('path') | 9 | var path = require('path') |
@@ -28,7 +31,7 @@ | |||
28 | var config = require('config') | 31 | var config = require('config') |
29 | var logger = require('./src/logger') | 32 | var logger = require('./src/logger') |
30 | var routes = require('./routes') | 33 | var routes = require('./routes') |
31 | var api = require('./routes/api') | 34 | var api = require('./routes/api/' + global.API_VERSION) |
32 | var utils = require('./src/utils') | 35 | var utils = require('./src/utils') |
33 | var videos = require('./src/videos') | 36 | var videos = require('./src/videos') |
34 | var webtorrent = require('./src/webTorrentNode') | 37 | var webtorrent = require('./src/webTorrentNode') |
@@ -88,9 +91,10 @@ | |||
88 | } | 91 | } |
89 | 92 | ||
90 | // ----------- Routes ----------- | 93 | // ----------- Routes ----------- |
91 | app.use('/api/videos', api.videos) | 94 | var api_route = '/api/' + global.API_VERSION |
92 | app.use('/api/remotevideos', api.remoteVideos) | 95 | app.use(api_route + '/videos', api.videos) |
93 | app.use('/api/pods', api.pods) | 96 | app.use(api_route + '/remotevideos', api.remoteVideos) |
97 | app.use(api_route + '/pods', api.pods) | ||
94 | 98 | ||
95 | // ----------- Tracker ----------- | 99 | // ----------- Tracker ----------- |
96 | 100 | ||
diff --git a/src/pods.js b/src/pods.js index 30d465ee5..db159a466 100644 --- a/src/pods.js +++ b/src/pods.js | |||
@@ -18,7 +18,7 @@ | |||
18 | // ----------- Private functions ----------- | 18 | // ----------- Private functions ----------- |
19 | 19 | ||
20 | function getForeignPodsList (url, callback) { | 20 | function getForeignPodsList (url, callback) { |
21 | var path = '/api/pods' | 21 | var path = '/api/' + global.API_VERSION + '/pods' |
22 | 22 | ||
23 | request.get(url + path, function (err, response, body) { | 23 | request.get(url + path, function (err, response, body) { |
24 | if (err) throw err | 24 | if (err) throw err |
@@ -143,7 +143,7 @@ | |||
143 | logger.debug('Make requests...') | 143 | logger.debug('Make requests...') |
144 | 144 | ||
145 | utils.makeMultipleRetryRequest( | 145 | utils.makeMultipleRetryRequest( |
146 | { method: 'POST', path: '/api/pods/', data: data }, | 146 | { method: 'POST', path: '/api/' + global.API_VERSION + '/pods/', data: data }, |
147 | 147 | ||
148 | pods_list, | 148 | pods_list, |
149 | 149 | ||
diff --git a/src/videos.js b/src/videos.js index 48ec19d4d..f787ae49c 100644 --- a/src/videos.js +++ b/src/videos.js | |||
@@ -73,7 +73,7 @@ | |||
73 | logger.debug('Sending this video Uri to friends...') | 73 | logger.debug('Sending this video Uri to friends...') |
74 | 74 | ||
75 | var data = { | 75 | var data = { |
76 | path: '/api/remotevideos/add', | 76 | path: '/api/' + global.API_VERSION + '/remotevideos/add', |
77 | method: 'POST', | 77 | method: 'POST', |
78 | data: params | 78 | data: params |
79 | } | 79 | } |
@@ -130,7 +130,7 @@ | |||
130 | } | 130 | } |
131 | 131 | ||
132 | var data = { | 132 | var data = { |
133 | path: '/api/remotevideos/remove', | 133 | path: '/api/' + global.API_VERSION + '/remotevideos/remove', |
134 | method: 'POST', | 134 | method: 'POST', |
135 | data: { | 135 | data: { |
136 | magnetUri: video.magnetUri | 136 | magnetUri: video.magnetUri |
diff --git a/test/api/friends.js b/test/api/friends.js index 033d3799a..845ccd1a8 100644 --- a/test/api/friends.js +++ b/test/api/friends.js | |||
@@ -9,7 +9,7 @@ | |||
9 | var utils = require('../utils') | 9 | var utils = require('../utils') |
10 | 10 | ||
11 | function getFriendsList (url, end) { | 11 | function getFriendsList (url, end) { |
12 | var path = '/api/pods/' | 12 | var path = '/api/v1/pods/' |
13 | 13 | ||
14 | request(url) | 14 | request(url) |
15 | .get(path) | 15 | .get(path) |
@@ -75,7 +75,7 @@ | |||
75 | }) | 75 | }) |
76 | } | 76 | } |
77 | 77 | ||
78 | var path = '/api/pods/makefriends' | 78 | var path = '/api/v1/pods/makefriends' |
79 | 79 | ||
80 | // The second pod make friend with the third | 80 | // The second pod make friend with the third |
81 | request(urls[1]) | 81 | request(urls[1]) |
diff --git a/test/api/multiplePods.js b/test/api/multiplePods.js index 3b69738f4..1edfc1ce3 100644 --- a/test/api/multiplePods.js +++ b/test/api/multiplePods.js | |||
@@ -11,7 +11,7 @@ | |||
11 | webtorrent.silent = true | 11 | webtorrent.silent = true |
12 | 12 | ||
13 | describe('Test multiple pods', function () { | 13 | describe('Test multiple pods', function () { |
14 | var path = '/api/videos' | 14 | var path = '/api/v1/videos' |
15 | var apps = [] | 15 | var apps = [] |
16 | var urls = [] | 16 | var urls = [] |
17 | var video_id = -1 | 17 | var video_id = -1 |
@@ -38,7 +38,7 @@ | |||
38 | 38 | ||
39 | before(function (done) { | 39 | before(function (done) { |
40 | this.timeout(30000) | 40 | this.timeout(30000) |
41 | var path_friends = '/api/pods/makefriends' | 41 | var path_friends = '/api/v1/pods/makefriends' |
42 | 42 | ||
43 | utils.runMultipleServers(3, function (apps_run, urls_run) { | 43 | utils.runMultipleServers(3, function (apps_run, urls_run) { |
44 | apps = apps_run | 44 | apps = apps_run |
diff --git a/test/api/singlePod.js b/test/api/singlePod.js index 5c4c892bb..bc9243c1c 100644 --- a/test/api/singlePod.js +++ b/test/api/singlePod.js | |||
@@ -3,6 +3,7 @@ | |||
3 | 3 | ||
4 | var request = require('supertest') | 4 | var request = require('supertest') |
5 | var chai = require('chai') | 5 | var chai = require('chai') |
6 | var fs = require('fs') | ||
6 | var expect = chai.expect | 7 | var expect = chai.expect |
7 | var webtorrent = require(__dirname + '/../../src/webTorrentNode') | 8 | var webtorrent = require(__dirname + '/../../src/webTorrentNode') |
8 | webtorrent.silent = true | 9 | webtorrent.silent = true |
@@ -10,7 +11,7 @@ | |||
10 | var utils = require('../utils') | 11 | var utils = require('../utils') |
11 | 12 | ||
12 | describe('Test a single pod', function () { | 13 | describe('Test a single pod', function () { |
13 | var path = '/api/videos' | 14 | var path = '/api/v1/videos' |
14 | var app = null | 15 | var app = null |
15 | var url = '' | 16 | var url = '' |
16 | var video_id = -1 | 17 | var video_id = -1 |
@@ -98,7 +99,13 @@ | |||
98 | .expect(204) | 99 | .expect(204) |
99 | .end(function (err, res) { | 100 | .end(function (err, res) { |
100 | if (err) throw err | 101 | if (err) throw err |
101 | done() | 102 | |
103 | fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) { | ||
104 | if (err) throw err | ||
105 | |||
106 | expect(files.length).to.equal(0) | ||
107 | done() | ||
108 | }) | ||
102 | }) | 109 | }) |
103 | }) | 110 | }) |
104 | 111 | ||