harmonize different ID types, improved the prefixes
This commit is contained in:
parent
f6b87daa27
commit
292c68a0a5
|
@ -129,7 +129,7 @@ function mapAuthorWithDBKey (mapperkey, mapper, callback)
|
|||
exports.createAuthor = function(name, callback)
|
||||
{
|
||||
//create the new author name
|
||||
var author = "g." + _randomString(16);
|
||||
var author = "a." + randomString(16);
|
||||
|
||||
//create the globalAuthors db entry
|
||||
var authorObj = {"colorId" : Math.floor(Math.random()*32), "name": name, "timestamp": new Date().getTime()};
|
||||
|
@ -193,11 +193,14 @@ exports.setAuthorName = function (author, name, callback)
|
|||
/**
|
||||
* Generates a random String with the given length. Is needed to generate the Author Ids
|
||||
*/
|
||||
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));
|
||||
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 pieces.join('');
|
||||
return randomstring;
|
||||
}
|
||||
|
|
|
@ -34,41 +34,11 @@ exports.doesGroupExist = function(groupID, callback)
|
|||
exports.createGroup = function(callback)
|
||||
{
|
||||
//search for non existing groupID
|
||||
var groupID;
|
||||
var foundNonExistingGroupID = false;
|
||||
async.whilst(
|
||||
function () { return !foundNonExistingGroupID; },
|
||||
function (callback)
|
||||
{
|
||||
//generate a random 10 digit groupID
|
||||
groupID = "";
|
||||
for(var i=0;i<10;i++)
|
||||
{
|
||||
groupID+=Math.floor(Math.random()*10);
|
||||
}
|
||||
|
||||
//check if this groupID already exisits
|
||||
exports.doesGroupExist(groupID, function(err, exists)
|
||||
{
|
||||
foundNonExistingGroupID = !exists;
|
||||
callback(err);
|
||||
})
|
||||
},
|
||||
//we found a non existing groupID or an error happend
|
||||
function (err)
|
||||
{
|
||||
//check for errors
|
||||
if(err)
|
||||
{
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
//create the group
|
||||
db.set("group:" + groupID, {pads: {}});
|
||||
callback(null, {groupID: groupID});
|
||||
}
|
||||
);
|
||||
var groupID = "g." + randomString(16);
|
||||
|
||||
//create the group
|
||||
db.set("group:" + groupID, {pads: {}});
|
||||
callback(null, {groupID: groupID});
|
||||
}
|
||||
|
||||
exports.createGroupIfNotExistsFor = function(groupMapper, callback)
|
||||
|
@ -183,11 +153,6 @@ exports.createGroupPad = function(groupID, padName, text, callback)
|
|||
{
|
||||
callback(err, {padID: padID});
|
||||
});
|
||||
|
||||
//check if groupID exists
|
||||
//check if pad already exists
|
||||
//create the pad
|
||||
//create the subentry in the padobject
|
||||
}
|
||||
|
||||
exports.listPads = function(groupID, callback)
|
||||
|
@ -214,3 +179,18 @@ exports.listPads = function(groupID, callback)
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random String with the given length. Is needed to generate the Author 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -380,12 +380,14 @@ function listSessionsWithDBKey (dbkey, 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;
|
||||
}
|
||||
|
||||
//checks if a number is an int
|
||||
|
|
|
@ -131,11 +131,14 @@ exports.handle = function(functionName, fields, req, res)
|
|||
/**
|
||||
* Generates a random String with the given length. Is needed to generate the Author Ids
|
||||
*/
|
||||
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));
|
||||
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 pieces.join('');
|
||||
return randomstring;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue