move randomString function into module

This commit is contained in:
booo 2012-01-28 13:24:58 +01:00
parent f7089bba20
commit a300bb6e92
8 changed files with 26 additions and 90 deletions

View file

@ -22,6 +22,8 @@ var ERR = require("async-stacktrace");
var db = require("./DB").db;
var async = require("async");
var randomString = require("../utils/randomstring");
/**
* returns a read only id for a pad
* @param {String} padId the id of the pad
@ -70,18 +72,3 @@ exports.getPadId = function(readOnlyId, callback)
{
db.get("readonly2pad:" + readOnlyId, callback);
}
/**
* Generates a random String with the given length. Is needed to generate the read only ids
*/
function randomString(len)
{
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var randomstring = '';
for (var i = 0; i < len; i++)
{
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum, rnum + 1);
}
return randomstring;
}