mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 14:47:12 -04:00
db/API: use jshint
This commit is contained in:
parent
224e82d8b0
commit
07626170d4
1 changed files with 66 additions and 66 deletions
132
node/db/API.js
132
node/db/API.js
|
@ -63,7 +63,7 @@ exports.listSessionsOfAuthor = sessionManager.listSessionsOfAuthor;
|
||||||
/************************/
|
/************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getText(padID, [rev]) returns the text of a pad
|
getText(padID, [rev]) returns the text of a pad
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -78,14 +78,14 @@ exports.getText = function(padID, rev, callback)
|
||||||
callback = rev;
|
callback = rev;
|
||||||
rev = undefined;
|
rev = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if rev is a number
|
//check if rev is a number
|
||||||
if(rev !== undefined && typeof rev != "number")
|
if(rev !== undefined && typeof rev != "number")
|
||||||
{
|
{
|
||||||
//try to parse the number
|
//try to parse the number
|
||||||
if(!isNaN(parseInt(rev)))
|
if(!isNaN(parseInt(rev, 10)))
|
||||||
{
|
{
|
||||||
rev = parseInt(rev);
|
rev = parseInt(rev, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -93,26 +93,26 @@ exports.getText = function(padID, rev, callback)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ensure this is not a negativ number
|
//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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ensure this is not a float value
|
//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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the pad
|
//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;
|
||||||
|
|
||||||
//the client asked for a special revision
|
//the client asked for a special revision
|
||||||
if(rev !== undefined)
|
if(rev !== undefined)
|
||||||
{
|
{
|
||||||
|
@ -122,16 +122,16 @@ exports.getText = function(padID, rev, callback)
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the text of this revision
|
//get the text of this revision
|
||||||
pad.getInternalRevisionAText(rev, function(err, atext)
|
pad.getInternalRevisionAText(rev, function(err, atext)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
data = {text: atext.text};
|
data = {text: atext.text};
|
||||||
|
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
//the client wants the latest text, lets return it to him
|
//the client wants the latest text, lets return it to him
|
||||||
else
|
else
|
||||||
|
@ -139,10 +139,10 @@ exports.getText = function(padID, rev, callback)
|
||||||
callback(null, {"text": pad.text()});
|
callback(null, {"text": pad.text()});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
setText(padID, text) sets the text of a pad
|
setText(padID, text) sets the text of a pad
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -151,22 +151,22 @@ Example returns:
|
||||||
{code: 1, message:"text too long", data: null}
|
{code: 1, message:"text too long", data: null}
|
||||||
*/
|
*/
|
||||||
exports.setText = function(padID, text, callback)
|
exports.setText = function(padID, text, callback)
|
||||||
{
|
{
|
||||||
//get the pad
|
//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;
|
||||||
|
|
||||||
//set the text
|
//set the text
|
||||||
pad.setText(text);
|
pad.setText(text);
|
||||||
|
|
||||||
//update the clients on the pad
|
//update the clients on the pad
|
||||||
padMessageHandler.updatePadClients(pad, callback);
|
padMessageHandler.updatePadClients(pad, callback);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getHTML(padID, [rev]) returns the html of a pad
|
getHTML(padID, [rev]) returns the html of a pad
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -178,14 +178,14 @@ exports.getHTML = function(padID, rev, callback)
|
||||||
if(typeof rev == "function")
|
if(typeof rev == "function")
|
||||||
{
|
{
|
||||||
callback = rev;
|
callback = rev;
|
||||||
rev = undefined;
|
rev = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rev !== undefined && typeof rev != "number")
|
if (rev !== undefined && typeof rev != "number")
|
||||||
{
|
{
|
||||||
if (!isNaN(parseInt(rev)))
|
if (!isNaN(parseInt(rev, 10)))
|
||||||
{
|
{
|
||||||
rev = parseInt(rev);
|
rev = parseInt(rev, 10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -209,7 +209,7 @@ exports.getHTML = function(padID, rev, callback)
|
||||||
getPadSafe(padID, true, function(err, pad)
|
getPadSafe(padID, true, function(err, pad)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
//the client asked for a special revision
|
//the client asked for a special revision
|
||||||
if(rev !== undefined)
|
if(rev !== undefined)
|
||||||
{
|
{
|
||||||
|
@ -219,8 +219,8 @@ exports.getHTML = function(padID, rev, callback)
|
||||||
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the html of this revision
|
//get the html of this revision
|
||||||
exportHtml.getPadHTML(pad, rev, function(err, html)
|
exportHtml.getPadHTML(pad, rev, function(err, html)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
@ -234,14 +234,14 @@ exports.getHTML = function(padID, rev, callback)
|
||||||
exportHtml.getPadHTML(pad, undefined, function (err, html)
|
exportHtml.getPadHTML(pad, undefined, function (err, html)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
data = {html: html};
|
data = {html: html};
|
||||||
|
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
exports.setHTML = function(padID, html, callback)
|
exports.setHTML = function(padID, html, callback)
|
||||||
{
|
{
|
||||||
|
@ -257,14 +257,14 @@ exports.setHTML = function(padID, html, callback)
|
||||||
padMessageHandler.updatePadClients(pad, callback);
|
padMessageHandler.updatePadClients(pad, callback);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/*****************/
|
/*****************/
|
||||||
/**PAD FUNCTIONS */
|
/**PAD FUNCTIONS */
|
||||||
/*****************/
|
/*****************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getRevisionsCount(padID) returns the number of revisions of this pad
|
getRevisionsCount(padID) returns the number of revisions of this pad
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -277,13 +277,13 @@ exports.getRevisionsCount = function(padID, callback)
|
||||||
getPadSafe(padID, true, function(err, pad)
|
getPadSafe(padID, true, function(err, pad)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
callback(null, {revisions: pad.getHeadRevisionNumber()});
|
callback(null, {revisions: pad.getHeadRevisionNumber()});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
createPad(padName [, text]) creates a new pad in this group
|
createPad(padName [, text]) creates a new pad in this group
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -291,24 +291,24 @@ Example returns:
|
||||||
{code: 1, message:"pad does already exist", data: null}
|
{code: 1, message:"pad does already exist", data: null}
|
||||||
*/
|
*/
|
||||||
exports.createPad = function(padID, text, callback)
|
exports.createPad = function(padID, text, callback)
|
||||||
{
|
{
|
||||||
//ensure there is no $ in the padID
|
//ensure there is no $ in the padID
|
||||||
if(padID.indexOf("$") != -1)
|
if(padID.indexOf("$") != -1)
|
||||||
{
|
{
|
||||||
callback(new customError("createPad can't create group pads","apierror"));
|
callback(new customError("createPad can't create group pads","apierror"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//create pad
|
//create pad
|
||||||
getPadSafe(padID, false, text, function(err)
|
getPadSafe(padID, false, text, function(err)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
deletePad(padID) deletes a pad
|
deletePad(padID) deletes a pad
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -320,13 +320,13 @@ exports.deletePad = function(padID, callback)
|
||||||
getPadSafe(padID, true, function(err, pad)
|
getPadSafe(padID, true, function(err, pad)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
pad.remove(callback);
|
pad.remove(callback);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getReadOnlyLink(padID) returns the read only link of a pad
|
getReadOnlyLink(padID) returns the read only link of a pad
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ exports.getReadOnlyID = function(padID, callback)
|
||||||
getPadSafe(padID, true, function(err)
|
getPadSafe(padID, true, function(err)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
//get the readonlyId
|
//get the readonlyId
|
||||||
readOnlyManager.getReadOnlyId(padID, function(err, readOnlyId)
|
readOnlyManager.getReadOnlyId(padID, function(err, readOnlyId)
|
||||||
{
|
{
|
||||||
|
@ -347,10 +347,10 @@ exports.getReadOnlyID = function(padID, callback)
|
||||||
callback(null, {readOnlyID: readOnlyId});
|
callback(null, {readOnlyID: readOnlyId});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
setPublicStatus(padID, publicStatus) sets a boolean for the public status of a pad
|
setPublicStatus(padID, publicStatus) sets a boolean for the public status of a pad
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -370,20 +370,20 @@ exports.setPublicStatus = function(padID, publicStatus, callback)
|
||||||
getPadSafe(padID, true, function(err, pad)
|
getPadSafe(padID, true, function(err, pad)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
//convert string to boolean
|
//convert string to boolean
|
||||||
if(typeof publicStatus == "string")
|
if(typeof publicStatus == "string")
|
||||||
publicStatus = publicStatus == "true" ? true : false;
|
publicStatus = publicStatus == "true" ? true : false;
|
||||||
|
|
||||||
//set the password
|
//set the password
|
||||||
pad.setPublicStatus(publicStatus);
|
pad.setPublicStatus(publicStatus);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
getPublicStatus(padID) return true of false
|
getPublicStatus(padID) return true of false
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -398,18 +398,18 @@ exports.getPublicStatus = function(padID, callback)
|
||||||
callback(new customError("You can only get/set the publicStatus of pads that belong to a group","apierror"));
|
callback(new customError("You can only get/set the publicStatus of pads that belong to a group","apierror"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the pad
|
//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;
|
||||||
|
|
||||||
callback(null, {publicStatus: pad.getPublicStatus()});
|
callback(null, {publicStatus: pad.getPublicStatus()});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
setPassword(padID, password) returns ok or a error message
|
setPassword(padID, password) returns ok or a error message
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -424,21 +424,21 @@ exports.setPassword = function(padID, password, callback)
|
||||||
callback(new customError("You can only get/set the password of pads that belong to a group","apierror"));
|
callback(new customError("You can only get/set the password of pads that belong to a group","apierror"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the pad
|
//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;
|
||||||
|
|
||||||
//set the password
|
//set the password
|
||||||
pad.setPassword(password);
|
pad.setPassword(password);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
isPasswordProtected(padID) returns true or false
|
isPasswordProtected(padID) returns true or false
|
||||||
|
|
||||||
Example returns:
|
Example returns:
|
||||||
|
|
||||||
|
@ -458,10 +458,10 @@ exports.isPasswordProtected = function(padID, callback)
|
||||||
getPadSafe(padID, true, function(err, pad)
|
getPadSafe(padID, true, function(err, pad)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
callback(null, {isPasswordProtected: pad.isPasswordProtected()});
|
callback(null, {isPasswordProtected: pad.isPasswordProtected()});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/******************************/
|
/******************************/
|
||||||
/** INTERNAL HELPER FUNCTIONS */
|
/** INTERNAL HELPER FUNCTIONS */
|
||||||
|
@ -469,8 +469,8 @@ exports.isPasswordProtected = function(padID, callback)
|
||||||
|
|
||||||
//checks if a number is an int
|
//checks if a number is an int
|
||||||
function is_int(value)
|
function is_int(value)
|
||||||
{
|
{
|
||||||
return (parseFloat(value) == parseInt(value)) && !isNaN(value)
|
return (parseFloat(value) == parseInt(value, 10)) && !isNaN(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
//gets a pad safe
|
//gets a pad safe
|
||||||
|
@ -488,26 +488,26 @@ function getPadSafe(padID, shouldExist, text, callback)
|
||||||
callback(new customError("padID is not a string","apierror"));
|
callback(new customError("padID is not a string","apierror"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if the padID maches the requirements
|
//check if the padID maches the requirements
|
||||||
if(!padManager.isValidPadId(padID))
|
if(!padManager.isValidPadId(padID))
|
||||||
{
|
{
|
||||||
callback(new customError("padID did not match requirements","apierror"));
|
callback(new customError("padID did not match requirements","apierror"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if the pad exists
|
//check if the pad exists
|
||||||
padManager.doesPadExists(padID, function(err, exists)
|
padManager.doesPadExists(padID, function(err, exists)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
//does not exist, but should
|
//does not exist, but should
|
||||||
if(exists == false && shouldExist == true)
|
if(!exists && shouldExist)
|
||||||
{
|
{
|
||||||
callback(new customError("padID does not exist","apierror"));
|
callback(new customError("padID does not exist","apierror"));
|
||||||
}
|
}
|
||||||
//does exists, but shouldn't
|
//does exists, but shouldn't
|
||||||
else if(exists == true && shouldExist == false)
|
else if(exists && !shouldExist)
|
||||||
{
|
{
|
||||||
callback(new customError("padID does already exist","apierror"));
|
callback(new customError("padID does already exist","apierror"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue