diff --git a/src/node/db/API.js b/src/node/db/API.js index 7a9ce41fa..a9e367f71 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -192,7 +192,7 @@ Example returns: {code: 0, message:"ok", data: {text:"Welcome Text"}} {code: 1, message:"padID does not exist", data: null} */ -exports.getHTML = function(padID, rev, callback) +function getHTML(padID, rev, wrapBody, callback) { if(typeof rev == "function") { @@ -243,8 +243,10 @@ exports.getHTML = function(padID, rev, callback) exportHtml.getPadHTML(pad, rev, function(err, html) { if(ERR(err, callback)) return; - html = "" +html; // adds HTML head - html += ""; + if(wrapBody) { + html = "" +html; // adds HTML head + html += ""; + } data = {html: html}; callback(null, data); }); @@ -255,8 +257,10 @@ exports.getHTML = function(padID, rev, callback) exportHtml.getPadHTML(pad, undefined, function (err, html) { if(ERR(err, callback)) return; - html = "" +html; // adds HTML head - html += ""; + if(wrapBody){ + html = "" +html; // adds HTML head + html += ""; + } data = {html: html}; callback(null, data); }); @@ -264,6 +268,11 @@ exports.getHTML = function(padID, rev, callback) }); } +exports.getHTML = { + "<1.2.7": function(padID, rev, callback){ return getHTML(padID, rev, false, callback); }, + ">=1.2.7": function(padID, rev, callback){ return getHTML(padID, rev, true, callback); } // wrap the body +}; + exports.setHTML = function(padID, html, callback) { //get the pad diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 9f86277a0..7c2d2f737 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -21,6 +21,7 @@ var ERR = require("async-stacktrace"); var fs = require("fs"); +var semver = require("semver"); var api = require("../db/API"); var padManager = require("../db/PadManager"); var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString; @@ -326,6 +327,24 @@ function callAPI(apiVersion, functionName, fields, req, res) } }); + var fn = api[functionName]; + + // If this is not a funcion it's a version=>function obj where version uses semver + if(typeof fn != "function") { + + // Get a proper version x.y.z + var v = apiVersion.split("."); + var apiVersion = [v[0]||'0', v[1]||'0', v[2]||'0'].join("."); + + // lookup the first version that satisfies the required version + for(var fnVersion in fn) { + if (semver.satisfies(apiVersion, fnVersion)) { + fn = fn[fnVersion]; + break; + } + } + } + //call the api function - api[functionName](functionParams[0],functionParams[1],functionParams[2],functionParams[3],functionParams[4]); + fn(functionParams[0],functionParams[1],functionParams[2],functionParams[3],functionParams[4]); } diff --git a/src/package.json b/src/package.json index 03df87f9b..64641031b 100644 --- a/src/package.json +++ b/src/package.json @@ -36,7 +36,8 @@ "tinycon" : "0.0.1", "underscore" : "1.3.1", "unorm" : "1.0.0", - "languages4translatewiki" : "0.1.3" + "languages4translatewiki" : "0.1.3", + "semver" : "1.1.3" }, "bin": { "etherpad-lite": "./node/server.js" }, "devDependencies": {