From a26918c69e2a8130333c395334eb45ba262e4aac Mon Sep 17 00:00:00 2001 From: Lorenzo Gil Sanchez Date: Thu, 17 Nov 2011 10:18:35 +0100 Subject: [PATCH] Hook the ImportHtml module into the API --- node/db/API.js | 22 ++++++++++++++++++++++ node/handler/APIHandler.js | 1 + 2 files changed, 23 insertions(+) diff --git a/node/db/API.js b/node/db/API.js index 2069ce688..c40c49cac 100644 --- a/node/db/API.js +++ b/node/db/API.js @@ -26,6 +26,8 @@ var authorManager = require("./AuthorManager"); var sessionManager = require("./SessionManager"); var async = require("async"); var exportHtml = require("../utils/ExportHtml"); +var importHtml = require("../utils/ImportHtml"); +var cleanText = require("./Pad").cleanText; /**********************/ /**GROUP FUNCTIONS*****/ @@ -254,6 +256,26 @@ exports.getHTML = function(padID, rev, callback) }); } +exports.setHTML = function(padID, html, callback) +{ + //get the pad + getPadSafe(padID, true, function(err, pad) + { + if(err) + { + callback(err); + return; + } + + // add a new changeset with the new html to the pad + importHtml.setPadHTML(pad, cleanText(html)); + + //update the clients on the pad + padMessageHandler.updatePadClients(pad, callback); + + }); +} + /*****************/ /**PAD FUNCTIONS */ /*****************/ diff --git a/node/handler/APIHandler.js b/node/handler/APIHandler.js index 57eeeb734..3e1bcdc51 100644 --- a/node/handler/APIHandler.js +++ b/node/handler/APIHandler.js @@ -51,6 +51,7 @@ var functions = { "getText" : ["padID", "rev"], "setText" : ["padID", "text"], "getHTML" : ["padID", "rev"], + "setHTML" : ["padID", "html"], "getRevisionsCount" : ["padID"], "deletePad" : ["padID"], "getReadOnlyID" : ["padID"],