mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 14:47:12 -04:00
db/PadManager: use jshint
This commit is contained in:
parent
ac74ba10d0
commit
928dfcb384
1 changed files with 19 additions and 19 deletions
|
@ -23,7 +23,7 @@ var customError = require("../utils/customError");
|
||||||
require("../db/Pad");
|
require("../db/Pad");
|
||||||
var db = require("./DB").db;
|
var db = require("./DB").db;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An Object containing all known Pads. Provides "get" and "set" functions,
|
* An Object containing all known Pads. Provides "get" and "set" functions,
|
||||||
* which should be used instead of indexing with brackets. These prepend a
|
* which should be used instead of indexing with brackets. These prepend a
|
||||||
* colon to the key, to avoid conflicting with built-in Object methods or with
|
* colon to the key, to avoid conflicting with built-in Object methods or with
|
||||||
|
@ -41,26 +41,26 @@ var globalPads = {
|
||||||
/**
|
/**
|
||||||
* Returns a Pad Object with the callback
|
* Returns a Pad Object with the callback
|
||||||
* @param id A String with the id of the pad
|
* @param id A String with the id of the pad
|
||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
*/
|
*/
|
||||||
exports.getPad = function(id, text, callback)
|
exports.getPad = function(id, text, callback)
|
||||||
{
|
{
|
||||||
//check if this is a valid padId
|
//check if this is a valid padId
|
||||||
if(!exports.isValidPadId(id))
|
if(!exports.isValidPadId(id))
|
||||||
{
|
{
|
||||||
callback(new customError(id + " is not a valid padId","apierror"));
|
callback(new customError(id + " is not a valid padId","apierror"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//make text an optional parameter
|
//make text an optional parameter
|
||||||
if(typeof text == "function")
|
if(typeof text === "function")
|
||||||
{
|
{
|
||||||
callback = text;
|
callback = text;
|
||||||
text = null;
|
text = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if this is a valid text
|
//check if this is a valid text
|
||||||
if(text != null)
|
if(text)
|
||||||
{
|
{
|
||||||
//check if text is a string
|
//check if text is a string
|
||||||
if(typeof text != "string")
|
if(typeof text != "string")
|
||||||
|
@ -68,7 +68,7 @@ exports.getPad = function(id, text, callback)
|
||||||
callback(new customError("text is not a string","apierror"));
|
callback(new customError("text is not a string","apierror"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if text is less than 100k chars
|
//check if text is less than 100k chars
|
||||||
if(text.length > 100000)
|
if(text.length > 100000)
|
||||||
{
|
{
|
||||||
|
@ -76,11 +76,11 @@ exports.getPad = function(id, text, callback)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var pad = globalPads.get(id);
|
var pad = globalPads.get(id);
|
||||||
|
|
||||||
//return pad if its already loaded
|
//return pad if its already loaded
|
||||||
if(pad != null)
|
if(pad)
|
||||||
{
|
{
|
||||||
callback(null, pad);
|
callback(null, pad);
|
||||||
}
|
}
|
||||||
|
@ -88,17 +88,17 @@ exports.getPad = function(id, text, callback)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pad = new Pad(id);
|
pad = new Pad(id);
|
||||||
|
|
||||||
//initalize the pad
|
//initalize the pad
|
||||||
pad.init(text, function(err)
|
pad.init(text, function(err)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
|
|
||||||
globalPads.set(id, pad);
|
globalPads.set(id, pad);
|
||||||
callback(null, pad);
|
callback(null, pad);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
//checks if a pad exists
|
//checks if a pad exists
|
||||||
exports.doesPadExists = function(padId, callback)
|
exports.doesPadExists = function(padId, callback)
|
||||||
|
@ -106,18 +106,18 @@ exports.doesPadExists = function(padId, callback)
|
||||||
db.get("pad:"+padId, function(err, value)
|
db.get("pad:"+padId, function(err, value)
|
||||||
{
|
{
|
||||||
if(ERR(err, callback)) return;
|
if(ERR(err, callback)) return;
|
||||||
callback(null, value != null);
|
callback(null, value ? true : false);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
exports.isValidPadId = function(padId)
|
exports.isValidPadId = function(padId)
|
||||||
{
|
{
|
||||||
return /^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/.test(padId);
|
return (/^(g.[a-zA-Z0-9]{16}\$)?[^$]{1,50}$/).test(padId);
|
||||||
}
|
};
|
||||||
|
|
||||||
//removes a pad from the array
|
//removes a pad from the array
|
||||||
exports.unloadPad = function(padId)
|
exports.unloadPad = function(padId)
|
||||||
{
|
{
|
||||||
if(globalPads.get(padId))
|
if(globalPads.get(padId))
|
||||||
globalPads.remove(padId);
|
globalPads.remove(padId);
|
||||||
}
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue