mirror of
https://github.com/seejohnrun/haste-server.git
synced 2025-12-14 06:25:56 +00:00
@@ -9,6 +9,7 @@ var DocumentHandler = function(options) {
|
||||
this.keyLength = options.keyLength || DocumentHandler.defaultKeyLength;
|
||||
this.maxLength = options.maxLength; // none by default
|
||||
this.store = options.store;
|
||||
this.keyGenerator = options.keyGenerator;
|
||||
};
|
||||
|
||||
DocumentHandler.defaultKeyLength = 10;
|
||||
@@ -87,7 +88,7 @@ DocumentHandler.prototype.handlePost = function(request, response) {
|
||||
|
||||
// Get a random key that hasn't been already used
|
||||
DocumentHandler.prototype.chooseKey = function(callback) {
|
||||
var key = this.randomKey();
|
||||
var key = this.keyGenerator.createKey(this.keyLength);
|
||||
var _this = this;
|
||||
this.store.get(key, function(ret) {
|
||||
if (ret) {
|
||||
@@ -98,14 +99,4 @@ DocumentHandler.prototype.chooseKey = function(callback) {
|
||||
});
|
||||
};
|
||||
|
||||
// Generate a random key
|
||||
DocumentHandler.prototype.randomKey = function() {
|
||||
var text = '';
|
||||
var keyspace = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
for (var i = 0; i < this.keyLength; i++) {
|
||||
text += keyspace.charAt(Math.floor(Math.random() * keyspace.length));
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
module.exports = DocumentHandler;
|
||||
|
||||
Reference in New Issue
Block a user