harmonize different ID types, improved the prefixes

This commit is contained in:
Peter 'Pita' Martischka 2011-08-10 14:24:21 +01:00
parent f6b87daa27
commit 292c68a0a5
5 changed files with 54 additions and 64 deletions

View file

@ -40,7 +40,7 @@ exports.getReadOnlyId = function (padId, callback)
//there is no readOnly Entry in the database, let's create one
if(dbReadOnlyId == null)
{
readOnlyId = randomString(10);
readOnlyId = "r." + randomString(16);
db.set("pad2readonly:" + padId, readOnlyId);
db.set("readonly2pad:" + readOnlyId, padId);
@ -74,10 +74,12 @@ exports.getPadId = function(readOnlyId, callback)
*/
function randomString(len)
{
// use only numbers and lowercase letters
var pieces = [];
for(var i=0;i<len;i++) {
pieces.push(Math.floor(Math.random()*36).toString(36).slice(-1));
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 pieces.join('');
return randomstring;
}