Add API versionning

This commit is contained in:
Chocobozzz 2015-11-06 17:34:15 +01:00
parent a6fa7ac141
commit f5a60a5138
11 changed files with 36 additions and 25 deletions

View file

@ -38,7 +38,7 @@
if (e.keyCode === 13) {
$.ajax({
url: '/api/videos/search/' + search,
url: '/api/v1/videos/search/' + search,
type: 'GET',
dataType: 'json',
success: function (videos) {
@ -51,7 +51,7 @@
// Join a new network
function makeFriends () {
$.ajax({
url: '/api/pods/makefriends',
url: '/api/v1/pods/makefriends',
type: 'GET',
dataType: 'json',
success: function () {
@ -140,7 +140,7 @@
$form_video.fileupload({
singleFileUploads: true,
multipart: true,
url: '/api/videos',
url: '/api/v1/videos',
autoupload: false,
add: function (e, data) {
var $text = $('<span></span>').addClass('name_file').text(data['files'][0]['name'])
@ -170,7 +170,7 @@
// Print the list of all the videos
function getVideos () {
$.ajax({
url: '/api/videos/',
url: '/api/v1/videos/',
dataType: 'json',
type: 'GET',
success: function (videos) {
@ -181,7 +181,7 @@
function removeVideo (video) {
$.ajax({
url: '/api/videos/' + video._id,
url: '/api/v1/videos/' + video._id,
type: 'DELETE',
success: function (response, status) {
getVideos()

View file

@ -3,8 +3,8 @@
var express = require('express')
var router = express.Router()
var middleware = require('../../middlewares')
var pods = require('../../src/pods')
var middleware = require('../../../middlewares')
var pods = require('../../../src/pods')
function listPods (req, res, next) {
pods.list(function (err, pods_list) {

View file

@ -3,8 +3,8 @@
var express = require('express')
var router = express.Router()
var middleware = require('../../middlewares')
var videos = require('../../src/videos')
var middleware = require('../../../middlewares')
var videos = require('../../../src/videos')
function addRemoteVideos (req, res, next) {
videos.addRemote(req.body.data, function (err, video) {

View file

@ -3,8 +3,8 @@
var express = require('express')
var router = express.Router()
var middleware = require('../../middlewares')
var videos = require('../../src/videos')
var middleware = require('../../../middlewares')
var videos = require('../../../src/videos')
function listVideos (req, res, next) {
videos.list(function (err, videos_list) {

View file

@ -1,6 +1,9 @@
;(function () {
'use strict'
// ----------- Constantes -----------
global.API_VERSION = 'v1'
// ----------- Node modules -----------
var express = require('express')
var path = require('path')
@ -28,7 +31,7 @@
var config = require('config')
var logger = require('./src/logger')
var routes = require('./routes')
var api = require('./routes/api')
var api = require('./routes/api/' + global.API_VERSION)
var utils = require('./src/utils')
var videos = require('./src/videos')
var webtorrent = require('./src/webTorrentNode')
@ -88,9 +91,10 @@
}
// ----------- Routes -----------
app.use('/api/videos', api.videos)
app.use('/api/remotevideos', api.remoteVideos)
app.use('/api/pods', api.pods)
var api_route = '/api/' + global.API_VERSION
app.use(api_route + '/videos', api.videos)
app.use(api_route + '/remotevideos', api.remoteVideos)
app.use(api_route + '/pods', api.pods)
// ----------- Tracker -----------

View file

@ -18,7 +18,7 @@
// ----------- Private functions -----------
function getForeignPodsList (url, callback) {
var path = '/api/pods'
var path = '/api/' + global.API_VERSION + '/pods'
request.get(url + path, function (err, response, body) {
if (err) throw err
@ -143,7 +143,7 @@
logger.debug('Make requests...')
utils.makeMultipleRetryRequest(
{ method: 'POST', path: '/api/pods/', data: data },
{ method: 'POST', path: '/api/' + global.API_VERSION + '/pods/', data: data },
pods_list,

View file

@ -73,7 +73,7 @@
logger.debug('Sending this video Uri to friends...')
var data = {
path: '/api/remotevideos/add',
path: '/api/' + global.API_VERSION + '/remotevideos/add',
method: 'POST',
data: params
}
@ -130,7 +130,7 @@
}
var data = {
path: '/api/remotevideos/remove',
path: '/api/' + global.API_VERSION + '/remotevideos/remove',
method: 'POST',
data: {
magnetUri: video.magnetUri

View file

@ -9,7 +9,7 @@
var utils = require('../utils')
function getFriendsList (url, end) {
var path = '/api/pods/'
var path = '/api/v1/pods/'
request(url)
.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
request(urls[1])

View file

@ -11,7 +11,7 @@
webtorrent.silent = true
describe('Test multiple pods', function () {
var path = '/api/videos'
var path = '/api/v1/videos'
var apps = []
var urls = []
var video_id = -1
@ -38,7 +38,7 @@
before(function (done) {
this.timeout(30000)
var path_friends = '/api/pods/makefriends'
var path_friends = '/api/v1/pods/makefriends'
utils.runMultipleServers(3, function (apps_run, urls_run) {
apps = apps_run

View file

@ -3,6 +3,7 @@
var request = require('supertest')
var chai = require('chai')
var fs = require('fs')
var expect = chai.expect
var webtorrent = require(__dirname + '/../../src/webTorrentNode')
webtorrent.silent = true
@ -10,7 +11,7 @@
var utils = require('../utils')
describe('Test a single pod', function () {
var path = '/api/videos'
var path = '/api/v1/videos'
var app = null
var url = ''
var video_id = -1
@ -98,7 +99,13 @@
.expect(204)
.end(function (err, res) {
if (err) throw err
done()
fs.readdir(__dirname + '/../../test1/uploads/', function (err, files) {
if (err) throw err
expect(files.length).to.equal(0)
done()
})
})
})