mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-14 19:16:54 -04:00
Added versioning to API functions
This commit is contained in:
parent
7c03bc2610
commit
f0bde9bf18
3 changed files with 36 additions and 7 deletions
|
@ -192,7 +192,7 @@ Example returns:
|
|||
{code: 0, message:"ok", data: {text:"Welcome <strong>Text</strong>"}}
|
||||
{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 = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head
|
||||
html += "</body></html>";
|
||||
if(wrapBody) {
|
||||
html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head
|
||||
html += "</body></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 = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head
|
||||
html += "</body></html>";
|
||||
if(wrapBody){
|
||||
html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head
|
||||
html += "</body></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
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue