diff options
author | Ted Mielczarek <ted@mielczarek.org> | 2015-10-19 12:58:47 -0400 |
---|---|---|
committer | Ted Mielczarek <ted@mielczarek.org> | 2015-10-19 15:27:09 -0400 |
commit | a675659dc28b95f8ef5664ffe5d82cd7cf2b2577 (patch) | |
tree | e8c6d997c2bf142586a469afe3a209fbf013f73e /src | |
parent | 504cc102a02396232bb9e29b159e3b5188f85a36 (diff) | |
download | etherpad-lite-a675659dc28b95f8ef5664ffe5d82cd7cf2b2577.zip |
Add an appendText API
Diffstat (limited to 'src')
-rw-r--r-- | src/node/db/API.js | 32 | ||||
-rw-r--r-- | src/node/db/Pad.js | 13 | ||||
-rw-r--r-- | src/node/handler/APIHandler.js | 53 |
3 files changed, 97 insertions, 1 deletions
diff --git a/src/node/db/API.js b/src/node/db/API.js index 87b6d747..237bcb0a 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -308,6 +308,38 @@ exports.setText = function(padID, text, callback) } /** +appendText(padID, text) appends text to a pad + +Example returns: + +{code: 0, message:"ok", data: null} +{code: 1, message:"padID does not exist", data: null} +{code: 1, message:"text too long", data: null} +*/ +exports.appendText = function(padID, text, callback) +{ + //text is required + if(typeof text != "string") + { + callback(new customError("text is no string","apierror")); + return; + } + + //get the pad + getPadSafe(padID, true, function(err, pad) + { + if(ERR(err, callback)) return; + + pad.appendText(text); + + //update the clients on the pad + padMessageHandler.updatePadClients(pad, callback); + }); +}; + + + +/** getHTML(padID, [rev]) returns the html of a pad Example returns: diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index eb6a3ed1..83e15e6d 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -303,6 +303,19 @@ Pad.prototype.setText = function setText(newText) { this.appendRevision(changeset); }; +Pad.prototype.appendText = function appendText(newText) { + //clean the new text + newText = exports.cleanText(newText); + + var oldText = this.text(); + + //create the changeset + var changeset = Changeset.makeSplice(oldText, oldText.length, 0, newText); + + //append the changeset + this.appendRevision(changeset); +}; + Pad.prototype.appendChatMessage = function appendChatMessage(text, userId, time) { this.chatHead++; //save the chat entry in the database diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index b4d24201..179c2b40 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -444,10 +444,61 @@ var version = , "getChatHead" : ["padID"] , "restoreRevision" : ["padID", "rev"] } +, "1.2.13": + { "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"] + , "getSavedRevisionsCount" : ["padID"] + , "listSavedRevisions" : ["padID"] + , "saveRevision" : ["padID", "rev"] + , "getRevisionChangeset" : ["padID", "rev"] + , "getLastEdited" : ["padID"] + , "deletePad" : ["padID"] + , "copyPad" : ["sourceID", "destinationID", "force"] + , "movePad" : ["sourceID", "destinationID", "force"] + , "getReadOnlyID" : ["padID"] + , "getPadID" : ["roID"] + , "setPublicStatus" : ["padID", "publicStatus"] + , "getPublicStatus" : ["padID"] + , "setPassword" : ["padID", "password"] + , "isPasswordProtected" : ["padID"] + , "listAuthorsOfPad" : ["padID"] + , "padUsersCount" : ["padID"] + , "getAuthorName" : ["authorID"] + , "padUsers" : ["padID"] + , "sendClientsMessage" : ["padID", "msg"] + , "listAllGroups" : [] + , "checkToken" : [] + , "appendChatMessage" : ["padID", "text", "authorID", "time"] + , "getChatHistory" : ["padID"] + , "getChatHistory" : ["padID", "start", "end"] + , "getChatHead" : ["padID"] + , "restoreRevision" : ["padID", "rev"] + , "appendText" : ["padID", "text"] + } }; // set the latest available API version here -exports.latestApiVersion = '1.2.12'; +exports.latestApiVersion = '1.2.13'; // exports the versions so it can be used by the new Swagger endpoint exports.version = version; |