mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
change if author really exist, before we set the author timestamp
This commit is contained in:
parent
5238eeae8a
commit
29dc8fdc31
1 changed files with 44 additions and 20 deletions
|
@ -32,17 +32,57 @@ exports.getAuthor4Token = function (token, callback)
|
||||||
{
|
{
|
||||||
var author;
|
var author;
|
||||||
|
|
||||||
async.waterfall([
|
async.series([
|
||||||
//try to get the author for this token
|
//try to get the author for this token
|
||||||
function(callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
db.get("token2author:" + token, callback);
|
db.get("token2author:" + token, function (err, _author)
|
||||||
|
{
|
||||||
|
author = _author;
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
function(value, callback)
|
function(callback)
|
||||||
{
|
{
|
||||||
//there is no author with this token, so create one
|
//there is no author with this token, so create one
|
||||||
if(value == null)
|
if(author == null)
|
||||||
{
|
{
|
||||||
|
author = createAuthor(token);
|
||||||
|
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
//there is a author with this token
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//check if there is also an author object for this token, if not, create one
|
||||||
|
db.get("globalAuthor:" + author, function(err, authorObject)
|
||||||
|
{
|
||||||
|
if(authorObject == null)
|
||||||
|
{
|
||||||
|
createAuthor(token);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//update the author time
|
||||||
|
db.setSub("globalAuthor:" + author, ["timestamp"], new Date().getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
], function(err)
|
||||||
|
{
|
||||||
|
callback(err, author);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal function that creates the database entry for an author
|
||||||
|
* @param {String} token The token
|
||||||
|
*/
|
||||||
|
function createAuthor (token)
|
||||||
|
{
|
||||||
//create the new author name
|
//create the new author name
|
||||||
author = "g." + _randomString(16);
|
author = "g." + _randomString(16);
|
||||||
|
|
||||||
|
@ -53,23 +93,7 @@ exports.getAuthor4Token = function (token, callback)
|
||||||
var authorObj = {colorId : Math.floor(Math.random()*32), name: null, timestamp: new Date().getTime()};
|
var authorObj = {colorId : Math.floor(Math.random()*32), name: null, timestamp: new Date().getTime()};
|
||||||
db.set("globalAuthor:" + author, authorObj);
|
db.set("globalAuthor:" + author, authorObj);
|
||||||
|
|
||||||
callback(null);
|
return author;
|
||||||
}
|
|
||||||
//there is a author with this token
|
|
||||||
else
|
|
||||||
{
|
|
||||||
author = value;
|
|
||||||
|
|
||||||
//update the author time
|
|
||||||
db.setSub("globalAuthor:" + author, ["timestamp"], new Date().getTime());
|
|
||||||
|
|
||||||
callback(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
], function(err)
|
|
||||||
{
|
|
||||||
callback(err, author);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue