]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add API versionning
authorChocobozzz <florian.bigard@gmail.com>
Fri, 6 Nov 2015 16:34:15 +0000 (17:34 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 6 Nov 2015 16:34:31 +0000 (17:34 +0100)
public/javascripts/index.js
routes/api/v1/index.js [moved from routes/api/index.js with 100% similarity]
routes/api/v1/pods.js [moved from routes/api/pods.js with 89% similarity]
routes/api/v1/remoteVideos.js [moved from routes/api/remoteVideos.js with 87% similarity]
routes/api/v1/videos.js [moved from routes/api/videos.js with 93% similarity]
server.js
src/pods.js
src/videos.js
test/api/friends.js
test/api/multiplePods.js
test/api/singlePod.js

index 95caf7eb4081ccfaf1e385bfad6ca03fdba9155d..c67e22c7bfe127c504e4d17e8d1242680b01d287 100644 (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 () {
     $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'])
   // Print the list of all the videos
   function getVideos () {
     $.ajax({
-      url: '/api/videos/',
+      url: '/api/v1/videos/',
       dataType: 'json',
       type: 'GET',
       success: function (videos) {
 
   function removeVideo (video) {
     $.ajax({
-      url: '/api/videos/' + video._id,
+      url: '/api/v1/videos/' + video._id,
       type: 'DELETE',
       success: function (response, status) {
         getVideos()
similarity index 100%
rename from routes/api/index.js
rename to routes/api/v1/index.js
similarity index 89%
rename from routes/api/pods.js
rename to routes/api/v1/pods.js
index 8fa29b4f797a7d643df4806bacb7bca26b297a38..961388fcb01029762955e06515d67d9044254a18 100644 (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) {
similarity index 87%
rename from routes/api/remoteVideos.js
rename to routes/api/v1/remoteVideos.js
index 2ae3ce5bc584064f370c5ce94e673213559547ee..88b8e879b9dd54ed8717747686013d6d32113052 100644 (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) {
similarity index 93%
rename from routes/api/videos.js
rename to routes/api/v1/videos.js
index 087fc96bc9dd39ff757a104802585410c3a079a9..246620ac6df1185030c18f661588393889eb6230 100644 (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) {
index 96c493f29d9ba9eaae6c1751d1704519c8e0af5f..d3718f8de31b59e99b6e9d98c2523376ab94ef44 100644 (file)
--- a/server.js
+++ b/server.js
@@ -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')
   }
 
   // ----------- 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 -----------
 
index 30d465ee5fbc8ae7451d14f113ddabf75c8cce21..db159a46610372b5d34f1d5266691186aa3ebfac 100644 (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
         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,
 
index 48ec19d4d5df05864abfe850104713f410f31777..f787ae49cddacfec8ba153244d6ea84170806720 100644 (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
         }
             }
 
             var data = {
-              path: '/api/remotevideos/remove',
+              path: '/api/' + global.API_VERSION + '/remotevideos/remove',
               method: 'POST',
               data: {
                 magnetUri: video.magnetUri
index 033d3799a2961b56528efc4ed8f52148e39d3975..845ccd1a8d0ec8e6d461afd22aecccb039ae3d31 100644 (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])
index 3b69738f4ebb7352e2431fdf42a8faa4f77c0f59..1edfc1ce3b8c485c8900c6a991779030f5c5e79a 100644 (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
index 5c4c892bba7221fb78a24f643876e5db57df6c08..bc9243c1c7fb302a926e9a996915157764967fdd 100644 (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
         .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()
+          })
         })
     })