diff --git a/doc/api/http_api.md b/doc/api/http_api.md index b9b5fedbb..0d2cc3756 100644 --- a/doc/api/http_api.md +++ b/doc/api/http_api.md @@ -419,3 +419,13 @@ returns ok when the current api token is valid *Example returns:* * `{"code":0,"message":"ok","data":null}` * `{"code":4,"message":"no or wrong API Key","data":null}` + +### Pads + +#### listAllPads() + * API >= 1.2.1 + +lists all pads on this epl instance + +*Example returns:* + * `{code: 0, message:"ok", data: ["testPad", "thePadsOfTheOthers"]}` diff --git a/src/node/db/API.js b/src/node/db/API.js index a26055a79..ee12d1d98 100644 --- a/src/node/db/API.js +++ b/src/node/db/API.js @@ -42,6 +42,12 @@ exports.deleteGroup = groupManager.deleteGroup; exports.listPads = groupManager.listPads; exports.createGroupPad = groupManager.createGroupPad; +/**********************/ +/**PADLIST FUNCTION****/ +/**********************/ + +exports.listAllPads = padManager.getPads; + /**********************/ /**AUTHOR FUNCTIONS****/ /**********************/ diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index 0914c175b..da1ce9e16 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -455,8 +455,7 @@ Pad.prototype.remove = function remove(callback) { //delete the pad entry and delete pad from padManager function(callback) { - db.remove("pad:"+padID); - padManager.unloadPad(padID); + padManager.removePad(padID); hooks.callAll("padRemove", {'padID':padID}); callback(); } diff --git a/src/node/db/PadManager.js b/src/node/db/PadManager.js index 5f08b1b1b..8cd69a83e 100644 --- a/src/node/db/PadManager.js +++ b/src/node/db/PadManager.js @@ -34,10 +34,59 @@ var db = require("./DB").db; */ var globalPads = { get: function (name) { return this[':'+name]; }, - set: function (name, value) { this[':'+name] = value; }, + set: function (name, value) + { + this[':'+name] = value; + padList.addPad(name); + }, remove: function (name) { delete this[':'+name]; } }; +var padList = { + list: [], + sorted : false, + init: function() + { + db.findKeys("pad:*", "*:*:*", function(err, dbData) + { + if(ERR(err)) return; + if(dbData != null){ + dbData.forEach(function(val){ + padList.addPad(val.replace(/pad:/,""),false); + }); + } + }); + return this; + }, + /** + * Returns all pads in alphabetical order as array. + */ + getPads: function(){ + if(!this.sorted){ + this.list=this.list.sort(); + this.sorted=true; + } + return this.list; + }, + addPad: function(name) + { + if(this.list.indexOf(name) == -1){ + this.list.push(name); + this.sorted=false; + } + }, + removePad: function(name) + { + var index=this.list.indexOf(name); + if(index>-1){ + this.list.splice(index,1); + this.sorted=false; + } + } +}; +//initialises the allknowing data structure +padList.init(); + /** * An array of padId transformations. These represent changes in pad name policy over * time, and allow us to "play back" these changes so legacy padIds can be found. @@ -109,6 +158,15 @@ exports.getPad = function(id, text, callback) } } +exports.getPads = function(callback) +{ + if(callback != null){ + callback(null,padList.getPads()); + }else{ + return padList.getPads(); + } +} + //checks if a pad exists exports.doesPadExists = function(padId, callback) { @@ -163,6 +221,15 @@ exports.isValidPadId = function(padId) return /^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/.test(padId); } +/** + * Removes the pad from database and unloads it. + */ +exports.removePad = function(padId){ + db.remove("pad:"+padId); + exports.unloadPad(padId); + padList.removePad(padId); +} + //removes a pad from the array exports.unloadPad = function(padId) { diff --git a/src/node/handler/APIHandler.js b/src/node/handler/APIHandler.js index 0bcd5f0c9..ae93e933f 100644 --- a/src/node/handler/APIHandler.js +++ b/src/node/handler/APIHandler.js @@ -138,6 +138,42 @@ var version = , "listAllGroups" : [] , "checkToken" : [] } +, "1.2.1": + { "createGroup" : [] + , "createGroupIfNotExistsFor" : ["groupMapper"] + , "deleteGroup" : ["groupID"] + , "listPads" : ["groupID"] + , "listAllPads" : [] + , "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"] + , "getRevisionsCount" : ["padID"] + , "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" : [] + } }; /**