db/API: use jshint

This commit is contained in:
booo 2011-12-22 11:54:32 +01:00
parent 224e82d8b0
commit 07626170d4

View file

@ -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:
@ -78,14 +78,14 @@ exports.getText = function(padID, rev, callback)
callback = rev;
rev = undefined;
}
//check if rev is a number
if(rev !== undefined && typeof rev != "number")
{
//try to parse the number
if(!isNaN(parseInt(rev)))
if(!isNaN(parseInt(rev, 10)))
{
rev = parseInt(rev);
rev = parseInt(rev, 10);
}
else
{
@ -93,26 +93,26 @@ exports.getText = function(padID, rev, callback)
return;
}
}
//ensure this is not a negativ number
if(rev !== undefined && rev < 0)
{
callback(new customError("rev is a negativ number","apierror"));
return;
}
//ensure this is not a float value
if(rev !== undefined && !is_int(rev))
{
callback(new customError("rev is a float value","apierror"));
return;
}
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
//the client asked for a special revision
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"));
return;
}
//get the text of this revision
pad.getInternalRevisionAText(rev, function(err, atext)
{
if(ERR(err, callback)) return;
data = {text: atext.text};
callback(null, data);
})
});
}
//the client wants the latest text, lets return it to him
else
@ -139,10 +139,10 @@ exports.getText = function(padID, rev, callback)
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:
@ -151,22 +151,22 @@ Example returns:
{code: 1, message:"text too long", data: null}
*/
exports.setText = function(padID, text, callback)
{
{
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
//set the text
pad.setText(text);
//update the clients on the pad
padMessageHandler.updatePadClients(pad, callback);
});
}
};
/**
getHTML(padID, [rev]) returns the html of a pad
getHTML(padID, [rev]) returns the html of a pad
Example returns:
@ -178,14 +178,14 @@ exports.getHTML = function(padID, rev, callback)
if(typeof rev == "function")
{
callback = rev;
rev = undefined;
rev = undefined;
}
if (rev !== undefined && typeof rev != "number")
{
if (!isNaN(parseInt(rev)))
if (!isNaN(parseInt(rev, 10)))
{
rev = parseInt(rev);
rev = parseInt(rev, 10);
}
else
{
@ -209,7 +209,7 @@ exports.getHTML = function(padID, rev, callback)
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
//the client asked for a special revision
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"));
return;
}
//get the html of this revision
//get the html of this revision
exportHtml.getPadHTML(pad, rev, function(err, html)
{
if(ERR(err, callback)) return;
@ -234,14 +234,14 @@ exports.getHTML = function(padID, rev, callback)
exportHtml.getPadHTML(pad, undefined, function (err, html)
{
if(ERR(err, callback)) return;
data = {html: html};
callback(null, data);
});
}
});
}
};
exports.setHTML = function(padID, html, callback)
{
@ -257,14 +257,14 @@ exports.setHTML = function(padID, html, callback)
padMessageHandler.updatePadClients(pad, callback);
});
}
};
/*****************/
/**PAD FUNCTIONS */
/*****************/
/**
getRevisionsCount(padID) returns the number of revisions of this pad
getRevisionsCount(padID) returns the number of revisions of this pad
Example returns:
@ -277,13 +277,13 @@ exports.getRevisionsCount = function(padID, callback)
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
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:
@ -291,24 +291,24 @@ Example returns:
{code: 1, message:"pad does already exist", data: null}
*/
exports.createPad = function(padID, text, callback)
{
{
//ensure there is no $ in the padID
if(padID.indexOf("$") != -1)
{
callback(new customError("createPad can't create group pads","apierror"));
return;
}
//create pad
getPadSafe(padID, false, text, function(err)
{
if(ERR(err, callback)) return;
callback();
});
}
};
/**
deletePad(padID) deletes a pad
deletePad(padID) deletes a pad
Example returns:
@ -320,13 +320,13 @@ exports.deletePad = function(padID, callback)
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
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:
@ -339,7 +339,7 @@ exports.getReadOnlyID = function(padID, callback)
getPadSafe(padID, true, function(err)
{
if(ERR(err, callback)) return;
//get the readonlyId
readOnlyManager.getReadOnlyId(padID, function(err, readOnlyId)
{
@ -347,10 +347,10 @@ exports.getReadOnlyID = function(padID, callback)
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:
@ -370,20 +370,20 @@ exports.setPublicStatus = function(padID, publicStatus, callback)
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
//convert string to boolean
if(typeof publicStatus == "string")
publicStatus = publicStatus == "true" ? true : false;
//set the password
pad.setPublicStatus(publicStatus);
callback();
});
}
};
/**
getPublicStatus(padID) return true of false
getPublicStatus(padID) return true of false
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"));
return;
}
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
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:
@ -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"));
return;
}
//get the pad
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
//set the password
pad.setPassword(password);
callback();
});
}
};
/**
isPasswordProtected(padID) returns true or false
isPasswordProtected(padID) returns true or false
Example returns:
@ -458,10 +458,10 @@ exports.isPasswordProtected = function(padID, callback)
getPadSafe(padID, true, function(err, pad)
{
if(ERR(err, callback)) return;
callback(null, {isPasswordProtected: pad.isPasswordProtected()});
});
}
};
/******************************/
/** INTERNAL HELPER FUNCTIONS */
@ -469,8 +469,8 @@ exports.isPasswordProtected = function(padID, callback)
//checks if a number is an int
function is_int(value)
{
return (parseFloat(value) == parseInt(value)) && !isNaN(value)
{
return (parseFloat(value) == parseInt(value, 10)) && !isNaN(value);
}
//gets a pad safe
@ -488,26 +488,26 @@ function getPadSafe(padID, shouldExist, text, callback)
callback(new customError("padID is not a string","apierror"));
return;
}
//check if the padID maches the requirements
if(!padManager.isValidPadId(padID))
{
callback(new customError("padID did not match requirements","apierror"));
return;
}
//check if the pad exists
padManager.doesPadExists(padID, function(err, exists)
{
if(ERR(err, callback)) return;
//does not exist, but should
if(exists == false && shouldExist == true)
if(!exists && shouldExist)
{
callback(new customError("padID does not exist","apierror"));
}
//does exists, but shouldn't
else if(exists == true && shouldExist == false)
else if(exists && !shouldExist)
{
callback(new customError("padID does already exist","apierror"));
}