update pad clients
parent
46bc328896
commit
9d39c9591a
|
@ -583,15 +583,16 @@ exports.deletePad = function(padID, callback)
|
|||
{code:0, message:"ok", data:null}
|
||||
{code: 1, message:"padID does not exist", data: null}
|
||||
*/
|
||||
exports.restoreRevision = function(padID, rev, callback)
|
||||
exports.restoreRevision = function (padID, rev, callback)
|
||||
{
|
||||
var Changeset = require("ep_etherpad-lite/static/js/Changeset");
|
||||
var padMessage = require("ep_etherpad-lite/node/handler/PadMessageHandler.js");
|
||||
|
||||
//check if rev is a number
|
||||
if(rev !== undefined && typeof rev != "number")
|
||||
if (rev !== undefined && typeof rev != "number")
|
||||
{
|
||||
//try to parse the number
|
||||
if(!isNaN(parseInt(rev)))
|
||||
if (!isNaN(parseInt(rev)))
|
||||
{
|
||||
rev = parseInt(rev);
|
||||
}
|
||||
|
@ -603,35 +604,35 @@ exports.restoreRevision = function(padID, rev, callback)
|
|||
}
|
||||
|
||||
//ensure this is not a negativ number
|
||||
if(rev !== undefined && rev < 0)
|
||||
if (rev !== undefined && rev < 0)
|
||||
{
|
||||
callback(new customError("rev is a negativ number","apierror"));
|
||||
callback(new customError("rev is a negativ number", "apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//ensure this is not a float value
|
||||
if(rev !== undefined && !is_int(rev))
|
||||
if (rev !== undefined && !is_int(rev))
|
||||
{
|
||||
callback(new customError("rev is a float value","apierror"));
|
||||
callback(new customError("rev is a float value", "apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
//get the pad
|
||||
getPadSafe(padID, true, function(err, pad)
|
||||
getPadSafe(padID, true, function (err, pad)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
if (ERR(err, callback)) return;
|
||||
|
||||
|
||||
//check if this is a valid revision
|
||||
if(rev > pad.getHeadRevisionNumber())
|
||||
if (rev > pad.getHeadRevisionNumber())
|
||||
{
|
||||
callback(new customError("rev is higher than the head revision of the pad","apierror"));
|
||||
callback(new customError("rev is higher than the head revision of the pad", "apierror"));
|
||||
return;
|
||||
}
|
||||
|
||||
pad.getInternalRevisionAText(rev, function(err, atext)
|
||||
pad.getInternalRevisionAText(rev, function (err, atext)
|
||||
{
|
||||
if(ERR(err, callback)) return;
|
||||
if (ERR(err, callback)) return;
|
||||
|
||||
var oldText = pad.text();
|
||||
atext.text += "\n";
|
||||
|
@ -657,17 +658,19 @@ exports.restoreRevision = function(padID, rev, callback)
|
|||
var builder = Changeset.builder(oldText.length);
|
||||
|
||||
// assemble each line into the builder
|
||||
eachAttribRun(atext.attribs, function(start, end, attribs)
|
||||
eachAttribRun(atext.attribs, function (start, end, attribs)
|
||||
{
|
||||
builder.insert(atext.text.substring(start, end), attribs);
|
||||
});
|
||||
|
||||
var lastNewlinePos = oldText.lastIndexOf('\n');
|
||||
if (lastNewlinePos < 0) {
|
||||
builder.remove(oldText.length-1,0);
|
||||
} else {
|
||||
builder.remove(lastNewlinePos, oldText.match(/\n/g).length-1);
|
||||
builder.remove(oldText.length - lastNewlinePos-1,0);
|
||||
if (lastNewlinePos < 0)
|
||||
{
|
||||
builder.remove(oldText.length - 1, 0);
|
||||
} else
|
||||
{
|
||||
builder.remove(lastNewlinePos, oldText.match(/\n/g).length - 1);
|
||||
builder.remove(oldText.length - lastNewlinePos - 1, 0);
|
||||
}
|
||||
|
||||
var changeset = builder.toString();
|
||||
|
@ -675,6 +678,9 @@ exports.restoreRevision = function(padID, rev, callback)
|
|||
//append the changeset
|
||||
pad.appendRevision(changeset);
|
||||
//
|
||||
padMessage.updatePadClients(pad, function ()
|
||||
{
|
||||
});
|
||||
callback(null, null);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue