summaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authors1341 <github@shmarya.net>2013-11-24 22:34:00 +0200
committers1341 <github@shmarya.net>2013-11-24 22:34:56 +0200
commit45e068048484296489352ad8ca5ad195fe164701 (patch)
tree43aa144c79f77f2e42128c35b681acc39738c66a /src/node
parent8b821d42a22646a4727bbd7a003e5eeea5aa369c (diff)
downloadetherpad-lite-45e068048484296489352ad8ca5ad195fe164701.zip
move copy/move pad into a new api version
Diffstat (limited to 'src/node')
-rw-r--r--src/node/handler/APIHandler.js64
1 files changed, 53 insertions, 11 deletions
diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js
index f2746b06..7206eb87 100644
--- a/src/node/handler/APIHandler.js
+++ b/src/node/handler/APIHandler.js
@@ -31,7 +31,7 @@ try
{
apikey = fs.readFileSync("./APIKEY.txt","utf8");
}
-catch(e)
+catch(e)
{
apikey = randomString(32);
fs.writeFileSync("./APIKEY.txt",apikey,"utf8");
@@ -240,6 +240,48 @@ var version =
, "getRevisionChangeset" : ["padID", "rev"]
, "getLastEdited" : ["padID"]
, "deletePad" : ["padID"]
+ , "getReadOnlyID" : ["padID"]
+ , "setPublicStatus" : ["padID", "publicStatus"]
+ , "getPublicStatus" : ["padID"]
+ , "setPassword" : ["padID", "password"]
+ , "isPasswordProtected" : ["padID"]
+ , "listAuthorsOfPad" : ["padID"]
+ , "padUsersCount" : ["padID"]
+ , "getAuthorName" : ["authorID"]
+ , "padUsers" : ["padID"]
+ , "sendClientsMessage" : ["padID", "msg"]
+ , "listAllGroups" : []
+ , "checkToken" : []
+ , "getChatHistory" : ["padID"]
+ , "getChatHistory" : ["padID", "start", "end"]
+ , "getChatHead" : ["padID"]
+ }
+, "1.2.9":
+ { "createGroup" : []
+ , "createGroupIfNotExistsFor" : ["groupMapper"]
+ , "deleteGroup" : ["groupID"]
+ , "listPads" : ["groupID"]
+ , "listAllPads" : []
+ , "createDiffHTML" : ["padID", "startRev", "endRev"]
+ , "createPad" : ["padID", "text"]
+ , "createGroupPad" : ["groupID", "padName", "text"]
+ , "createAuthor" : ["name"]
+ , "createAuthorIfNotExistsFor": ["authorMapper" , "name"]
+ , "listPadsOfAuthor" : ["authorID"]
+ , "createSession" : ["groupID", "authorID", "validUntil"]
+ , "deleteSession" : ["sessionID"]
+ , "getSessionInfo" : ["sessionID"]
+ , "listSessionsOfGroup" : ["groupID"]
+ , "listSessionsOfAuthor" : ["authorID"]
+ , "getText" : ["padID", "rev"]
+ , "setText" : ["padID", "text"]
+ , "getHTML" : ["padID", "rev"]
+ , "setHTML" : ["padID", "html"]
+ , "getAttributePool" : ["padID"]
+ , "getRevisionsCount" : ["padID"]
+ , "getRevisionChangeset" : ["padID", "rev"]
+ , "getLastEdited" : ["padID"]
+ , "deletePad" : ["padID"]
, "copyPad" : ["sourceID", "destinationID", "force"]
, "movePad" : ["sourceID", "destinationID", "force"]
, "getReadOnlyID" : ["padID"]
@@ -261,7 +303,7 @@ var version =
};
// set the latest available API version here
-exports.latestApiVersion = '1.2.7';
+exports.latestApiVersion = '1.2.9';
// exports the versions so it can be used by the new Swagger endpoint
exports.version = version;
@@ -285,7 +327,7 @@ exports.handle = function(apiVersion, functionName, fields, req, res)
break;
}
}
-
+
//say goodbye if this is an unkown API version
if(!isKnownApiVersion)
{
@@ -293,7 +335,7 @@ exports.handle = function(apiVersion, functionName, fields, req, res)
res.send({code: 3, message: "no such api version", data: null});
return;
}
-
+
//check if this is a valid function name
var isKnownFunctionname = false;
for(var knownFunctionname in version[apiVersion])
@@ -304,17 +346,17 @@ exports.handle = function(apiVersion, functionName, fields, req, res)
break;
}
}
-
+
//say goodbye if this is a unkown function
if(!isKnownFunctionname)
{
res.send({code: 3, message: "no such function", data: null});
return;
}
-
+
//check the api key!
fields["apikey"] = fields["apikey"] || fields["api_key"];
-
+
if(fields["apikey"] != apikey.trim())
{
res.send({code: 4, message: "no or wrong API Key", data: null});
@@ -351,16 +393,16 @@ function callAPI(apiVersion, functionName, fields, req, res)
var functionParams = version[apiVersion][functionName].map(function (field) {
return fields[field]
})
-
+
//add a callback function to handle the response
functionParams.push(function(err, data)
- {
+ {
// no error happend, everything is fine
if(err == null)
{
if(!data)
data = null;
-
+
res.send({code: 0, message: "ok", data: data});
}
// parameters were wrong and the api stopped execution, pass the error
@@ -375,7 +417,7 @@ function callAPI(apiVersion, functionName, fields, req, res)
ERR(err);
}
});
-
+
//call the api function
api[functionName].apply(this, functionParams);
}