diff --git a/src/node/db/API.js b/src/node/db/API.js index be3e73486..267e5b74a 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -342,19 +342,25 @@ exports.appendText = function(padID, text, callback) /** -getHTML(padID, [rev]) returns the html of a pad +getHTML(padID, [rev], [authorColor]) returns the html of a pad 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) +exports.getHTML = function(padID, rev, authorColor, callback) { +console.log("tits"); +console.log("authorColor", authorColor); + if(typeof authorColor == "function"){ + callback = authorColor; + authorColor = undefined; + } if(typeof rev == "function") { callback = rev; - rev = undefined; + rev = undefined; } if (rev !== undefined && typeof rev != "number") @@ -397,7 +403,7 @@ exports.getHTML = function(padID, rev, callback) } //get the html of this revision - exportHtml.getPadHTML(pad, rev, function(err, html) + exportHtml.getPadHTML(pad, rev, authorColor, function(err, html) { if(ERR(err, callback)) return; html = "" +html; // adds HTML head @@ -409,7 +415,7 @@ exports.getHTML = function(padID, rev, callback) //the client wants the latest text, lets return it to him else { - exportHtml.getPadHTML(pad, undefined, function (err, html) + exportHtml.getPadHTML(pad, undefined, authorColor, function (err, html) { if(ERR(err, callback)) return; html = "" +html; // adds HTML head diff --git a/src/node/db/PadManager.js b/src/node/db/PadManager.js index 2ecd6e274..645620ef1 100644 --- a/src/node/db/PadManager.js +++ b/src/node/db/PadManager.js @@ -120,7 +120,7 @@ var padIdTransforms = [ * @param {Function} callback */ exports.getPad = function(id, text, callback) -{ +{ //check if this is a valid padId if(!exports.isValidPadId(id)) { @@ -144,7 +144,7 @@ exports.getPad = function(id, text, callback) callback(new customError("text is not a string","apierror")); return; } - + //check if text is less than 100k chars if(text.length > 100000) { diff --git a/src/node/handler/.APIHandler.js.swp b/src/node/handler/.APIHandler.js.swp new file mode 100644 index 000000000..526ef916c Binary files /dev/null and b/src/node/handler/.APIHandler.js.swp differ diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 179c2b404..0fa182779 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -495,10 +495,61 @@ var version = , "restoreRevision" : ["padID", "rev"] , "appendText" : ["padID", "text"] } +, "1.2.14": + { "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", "authorColor"] + , "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.13'; +exports.latestApiVersion = '1.2.14'; // exports the versions so it can be used by the new Swagger endpoint exports.version = version; diff --git a/src/node/utils/.ExportTxt.js.swp b/src/node/utils/.ExportTxt.js.swp new file mode 100644 index 000000000..2b237c9f7 Binary files /dev/null and b/src/node/utils/.ExportTxt.js.swp differ diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index 836165b16..4fde2e888 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -25,7 +25,7 @@ var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks'); var _analyzeLine = require('./ExportHelper')._analyzeLine; var _encodeWhitespace = require('./ExportHelper')._encodeWhitespace; -function getPadHTML(pad, revNum, callback) +function getPadHTML(pad, revNum, authorColors, callback) { var atext = pad.atext; var html; @@ -53,7 +53,7 @@ function getPadHTML(pad, revNum, callback) function (callback) { - html = getHTMLFromAtext(pad, atext); + html = getHTMLFromAtext(pad, atext, authorColors); callback(null); }], // run final callback diff --git a/tests/backend/specs/api/.pad.js.swp b/tests/backend/specs/api/.pad.js.swp new file mode 100644 index 000000000..e6def3dfa Binary files /dev/null and b/tests/backend/specs/api/.pad.js.swp differ diff --git a/tests/backend/specs/api/pad.js b/tests/backend/specs/api/pad.js index 1db90580e..943a37bfe 100644 --- a/tests/backend/specs/api/pad.js +++ b/tests/backend/specs/api/pad.js @@ -10,7 +10,7 @@ var filePath = path.join(__dirname, '../../../../APIKEY.txt'); var apiKey = fs.readFileSync(filePath, {encoding: 'utf-8'}); apiKey = apiKey.replace(/\n$/, ""); -var apiVersion = 1; +var apiVersion = "1.2.14"; var testPadId = makeid(); var lastEdited = ""; var text = generateLongText(); @@ -84,7 +84,8 @@ describe('Permission', function(){ -> setHTML(padID) -- Should fail on invalid HTML -> setHTML(padID) *3 -- Should fail on invalid HTML -> getHTML(padID) -- Should return HTML close to posted HTML - -> createPad -- Tries to create pads with bad url characters + -> getHTML(padID, authorColor) -- Should return HTML close to posted HTML with some Author markup + -> createPad -- Tries to create pads with bad url characters */ @@ -200,7 +201,9 @@ describe('getText', function(){ describe('setText', function(){ it('creates a new Pad with text', function(done) { - api.get(endPoint('setText')+"&padID="+testPadId+"&text=testTextTwo") + var textString = "testText\tTwo"; // note the \t to emualte a tab + console.warn("Set text as ", textString); + api.get(endPoint('setText')+"&padID="+testPadId+"&text="+textString) .expect(function(res){ if(res.body.code !== 0) throw new Error("Pad setting text failed"); }) @@ -213,7 +216,8 @@ describe('getText', function(){ it('gets the Pad text', function(done) { api.get(endPoint('getText')+"&padID="+testPadId) .expect(function(res){ - if(res.body.data.text !== "testTextTwo\n") throw new Error("Setting Text") + var expectedString = "testText Two\n"; + if(res.body.data.text !== expectedString) throw new Error("Getting Text error") }) .expect('Content-Type', /json/) .expect(200, done) @@ -545,6 +549,19 @@ describe('getHTML', function(){ }); }) +describe('getHTML', function(){ + it('Gets the HTML of a Pad and include author info', function(done) { + api.get(endPoint('getHTML')+"&padID="+testPadId+"&authorColor=true") + .expect(function(res){ + var html = res.body.data.html; + console.warn("html", html); + if(html !== html) throw new Error("Imported HTML does not match served HTML") + }) + .expect('Content-Type', /json/) + .expect(200, done) + }); +}) + describe('createPad', function(){ it('errors if pad can be created', function(done) { var badUrlChars = ["/", "%23", "%3F", "%26"];