Add API versionning
This commit is contained in:
parent
a6fa7ac141
commit
f5a60a5138
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
if (e.keyCode === 13) {
|
if (e.keyCode === 13) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/videos/search/' + search,
|
url: '/api/v1/videos/search/' + search,
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function (videos) {
|
success: function (videos) {
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
// Join a new network
|
// Join a new network
|
||||||
function makeFriends () {
|
function makeFriends () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/pods/makefriends',
|
url: '/api/v1/pods/makefriends',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function () {
|
success: function () {
|
||||||
|
@ -140,7 +140,7 @@
|
||||||
$form_video.fileupload({
|
$form_video.fileupload({
|
||||||
singleFileUploads: true,
|
singleFileUploads: true,
|
||||||
multipart: true,
|
multipart: true,
|
||||||
url: '/api/videos',
|
url: '/api/v1/videos',
|
||||||
autoupload: false,
|
autoupload: false,
|
||||||
add: function (e, data) {
|
add: function (e, data) {
|
||||||
var $text = $('<span></span>').addClass('name_file').text(data['files'][0]['name'])
|
var $text = $('<span></span>').addClass('name_file').text(data['files'][0]['name'])
|
||||||
|
@ -170,7 +170,7 @@
|
||||||
// Print the list of all the videos
|
// Print the list of all the videos
|
||||||
function getVideos () {
|
function getVideos () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/videos/',
|
url: '/api/v1/videos/',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
success: function (videos) {
|
success: function (videos) {
|
||||||
|
@ -181,7 +181,7 @@
|
||||||
|
|
||||||
function removeVideo (video) {
|
function removeVideo (video) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/videos/' + video._id,
|
url: '/api/v1/videos/' + video._id,
|
||||||
type: 'DELETE',
|
type: 'DELETE',
|
||||||
success: function (response, status) {
|
success: function (response, status) {
|
||||||
getVideos()
|
getVideos()
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
var express = require('express')
|
var express = require('express')
|
||||||
var router = express.Router()
|
var router = express.Router()
|
||||||
var middleware = require('../../middlewares')
|
var middleware = require('../../../middlewares')
|
||||||
var pods = require('../../src/pods')
|
var pods = require('../../../src/pods')
|
||||||
|
|
||||||
function listPods (req, res, next) {
|
function listPods (req, res, next) {
|
||||||
pods.list(function (err, pods_list) {
|
pods.list(function (err, pods_list) {
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
var express = require('express')
|
var express = require('express')
|
||||||
var router = express.Router()
|
var router = express.Router()
|
||||||
var middleware = require('../../middlewares')
|
var middleware = require('../../../middlewares')
|
||||||
var videos = require('../../src/videos')
|
var videos = require('../../../src/videos')
|
||||||
|
|
||||||
function addRemoteVideos (req, res, next) {
|
function addRemoteVideos (req, res, next) {
|
||||||
videos.addRemote(req.body.data, function (err, video) {
|
videos.addRemote(req.body.data, function (err, video) {
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
var express = require('express')
|
var express = require('express')
|
||||||
var router = express.Router()
|
var router = express.Router()
|
||||||
var middleware = require('../../middlewares')
|
var middleware = require('../../../middlewares')
|
||||||
var videos = require('../../src/videos')
|
var videos = require('../../../src/videos')
|
||||||
|
|
||||||
function listVideos (req, res, next) {
|
function listVideos (req, res, next) {
|
||||||
videos.list(function (err, videos_list) {
|
videos.list(function (err, videos_list) {
|
12
server.js
12
server.js
|
@ -1,6 +1,9 @@
|
||||||
;(function () {
|
;(function () {
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
// ----------- Constantes -----------
|
||||||
|
global.API_VERSION = 'v1'
|
||||||
|
|
||||||
// ----------- Node modules -----------
|
// ----------- Node modules -----------
|
||||||
var express = require('express')
|
var express = require('express')
|
||||||
var path = require('path')
|
var path = require('path')
|
||||||
|
@ -28,7 +31,7 @@
|
||||||
var config = require('config')
|
var config = require('config')
|
||||||
var logger = require('./src/logger')
|
var logger = require('./src/logger')
|
||||||
var routes = require('./routes')
|
var routes = require('./routes')
|
||||||
var api = require('./routes/api')
|
var api = require('./routes/api/' + global.API_VERSION)
|
||||||
var utils = require('./src/utils')
|
var utils = require('./src/utils')
|
||||||
var videos = require('./src/videos')
|
var videos = require('./src/videos')
|
||||||
var webtorrent = require('./src/webTorrentNode')
|
var webtorrent = require('./src/webTorrentNode')
|
||||||
|
@ -88,9 +91,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------- Routes -----------
|
// ----------- Routes -----------
|
||||||
app.use('/api/videos', api.videos)
|
var api_route = '/api/' + global.API_VERSION
|
||||||
app.use('/api/remotevideos', api.remoteVideos)
|
app.use(api_route + '/videos', api.videos)
|
||||||
app.use('/api/pods', api.pods)
|
app.use(api_route + '/remotevideos', api.remoteVideos)
|
||||||
|
app.use(api_route + '/pods', api.pods)
|
||||||
|
|
||||||
// ----------- Tracker -----------
|
// ----------- Tracker -----------
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
// ----------- Private functions -----------
|
// ----------- Private functions -----------
|
||||||
|
|
||||||
function getForeignPodsList (url, callback) {
|
function getForeignPodsList (url, callback) {
|
||||||
var path = '/api/pods'
|
var path = '/api/' + global.API_VERSION + '/pods'
|
||||||
|
|
||||||
request.get(url + path, function (err, response, body) {
|
request.get(url + path, function (err, response, body) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
@ -143,7 +143,7 @@
|
||||||
logger.debug('Make requests...')
|
logger.debug('Make requests...')
|
||||||
|
|
||||||
utils.makeMultipleRetryRequest(
|
utils.makeMultipleRetryRequest(
|
||||||
{ method: 'POST', path: '/api/pods/', data: data },
|
{ method: 'POST', path: '/api/' + global.API_VERSION + '/pods/', data: data },
|
||||||
|
|
||||||
pods_list,
|
pods_list,
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
logger.debug('Sending this video Uri to friends...')
|
logger.debug('Sending this video Uri to friends...')
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
path: '/api/remotevideos/add',
|
path: '/api/' + global.API_VERSION + '/remotevideos/add',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: params
|
data: params
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
path: '/api/remotevideos/remove',
|
path: '/api/' + global.API_VERSION + '/remotevideos/remove',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
magnetUri: video.magnetUri
|
magnetUri: video.magnetUri
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
var utils = require('../utils')
|
var utils = require('../utils')
|
||||||
|
|
||||||
function getFriendsList (url, end) {
|
function getFriendsList (url, end) {
|
||||||
var path = '/api/pods/'
|
var path = '/api/v1/pods/'
|
||||||
|
|
||||||
request(url)
|
request(url)
|
||||||
.get(path)
|
.get(path)
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = '/api/pods/makefriends'
|
var path = '/api/v1/pods/makefriends'
|
||||||
|
|
||||||
// The second pod make friend with the third
|
// The second pod make friend with the third
|
||||||
request(urls[1])
|
request(urls[1])
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
webtorrent.silent = true
|
webtorrent.silent = true
|
||||||
|
|
||||||
describe('Test multiple pods', function () {
|
describe('Test multiple pods', function () {
|
||||||
var path = '/api/videos'
|
var path = '/api/v1/videos'
|
||||||
var apps = []
|
var apps = []
|
||||||
var urls = []
|
var urls = []
|
||||||
var video_id = -1
|
var video_id = -1
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
this.timeout(30000)
|
this.timeout(30000)
|
||||||
var path_friends = '/api/pods/makefriends'
|
var path_friends = '/api/v1/pods/makefriends'
|
||||||
|
|
||||||
utils.runMultipleServers(3, function (apps_run, urls_run) {
|
utils.runMultipleServers(3, function (apps_run, urls_run) {
|
||||||
apps = apps_run
|
apps = apps_run
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
var request = require('supertest')
|
var request = require('supertest')
|
||||||
var chai = require('chai')
|
var chai = require('chai')
|
||||||
|
var fs = require('fs')
|
||||||
var expect = chai.expect
|
var expect = chai.expect
|
||||||
var webtorrent = require(__dirname + '/../../src/webTorrentNode')
|
var webtorrent = require(__dirname + '/../../src/webTorrentNode')
|
||||||
webtorrent.silent = true
|
webtorrent.silent = true
|
||||||
|
@ -10,7 +11,7 @@
|
||||||
var utils = require('../utils')
|
var utils = require('../utils')
|
||||||
|
|
||||||
describe('Test a single pod', function () {
|
describe('Test a single pod', function () {
|
||||||
var path = '/api/videos'
|
var path = '/api/v1/videos'
|
||||||
var app = null
|
var app = null
|
||||||
var url = ''
|
var url = ''
|
||||||
var video_id = -1
|
var video_id = -1
|
||||||
|
@ -98,9 +99,15 @@
|
||||||
.expect(204)
|
.expect(204)
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
|
|
||||||
|
fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
|
||||||
|
if (err) throw err
|
||||||
|
|
||||||
|
expect(files.length).to.equal(0)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('Should not have videos', function (done) {
|
it('Should not have videos', function (done) {
|
||||||
request(url)
|
request(url)
|
||||||
|
|
Loading…
Reference in New Issue