mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-15 03:26:53 -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: 0, message:"ok", data: {text:"Welcome <strong>Text</strong>"}}
|
||||||
{code: 1, message:"padID does not exist", data: null}
|
{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")
|
if(typeof rev == "function")
|
||||||
{
|
{
|
||||||
|
@ -243,8 +243,10 @@ exports.getHTML = function(padID, rev, callback)
|
||||||
exportHtml.getPadHTML(pad, rev, function(err, html)
|
exportHtml.getPadHTML(pad, rev, function(err, html)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
if(wrapBody) {
|
||||||
html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head
|
html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head
|
||||||
html += "</body></html>";
|
html += "</body></html>";
|
||||||
|
}
|
||||||
data = {html: html};
|
data = {html: html};
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
});
|
});
|
||||||
|
@ -255,8 +257,10 @@ exports.getHTML = function(padID, rev, callback)
|
||||||
exportHtml.getPadHTML(pad, undefined, function (err, html)
|
exportHtml.getPadHTML(pad, undefined, function (err, html)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
if(wrapBody){
|
||||||
html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head
|
html = "<!DOCTYPE HTML><html><body>" +html; // adds HTML head
|
||||||
html += "</body></html>";
|
html += "</body></html>";
|
||||||
|
}
|
||||||
data = {html: html};
|
data = {html: html};
|
||||||
callback(null, data);
|
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)
|
exports.setHTML = function(padID, html, callback)
|
||||||
{
|
{
|
||||||
//get the pad
|
//get the pad
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
var ERR = require("async-stacktrace");
|
var ERR = require("async-stacktrace");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
var semver = require("semver");
|
||||||
var api = require("../db/API");
|
var api = require("../db/API");
|
||||||
var padManager = require("../db/PadManager");
|
var padManager = require("../db/PadManager");
|
||||||
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
|
||||||
|
@ -326,6 +327,24 @@ function callAPI(apiVersion, functionName, fields, req, res)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//call the api function
|
var fn = api[functionName];
|
||||||
api[functionName](functionParams[0],functionParams[1],functionParams[2],functionParams[3],functionParams[4]);
|
|
||||||
|
// 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
|
||||||
|
fn(functionParams[0],functionParams[1],functionParams[2],functionParams[3],functionParams[4]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,8 @@
|
||||||
"tinycon" : "0.0.1",
|
"tinycon" : "0.0.1",
|
||||||
"underscore" : "1.3.1",
|
"underscore" : "1.3.1",
|
||||||
"unorm" : "1.0.0",
|
"unorm" : "1.0.0",
|
||||||
"languages4translatewiki" : "0.1.3"
|
"languages4translatewiki" : "0.1.3",
|
||||||
|
"semver" : "1.1.3"
|
||||||
},
|
},
|
||||||
"bin": { "etherpad-lite": "./node/server.js" },
|
"bin": { "etherpad-lite": "./node/server.js" },
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue