mirror of
https://github.com/SunRed/haste-server.git
synced 2024-11-23 17:50:19 +01:00
Added random keys
This commit is contained in:
parent
f935ac56c2
commit
cf384cd0fd
1 changed files with 13 additions and 2 deletions
|
@ -9,6 +9,7 @@ var DocumentHandler = function() {
|
||||||
// TODO implement with FS backend
|
// TODO implement with FS backend
|
||||||
DocumentHandler.documents = {};
|
DocumentHandler.documents = {};
|
||||||
|
|
||||||
|
// Handle retrieving a document
|
||||||
DocumentHandler.prototype.handleGet = function(key, response) {
|
DocumentHandler.prototype.handleGet = function(key, response) {
|
||||||
if (DocumentHandler.documents[key]) {
|
if (DocumentHandler.documents[key]) {
|
||||||
winston.verbose('retrieved document', { key: key });
|
winston.verbose('retrieved document', { key: key });
|
||||||
|
@ -22,8 +23,9 @@ DocumentHandler.prototype.handleGet = function(key, response) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle adding a new Document
|
||||||
DocumentHandler.prototype.handlePost = function(request, response) {
|
DocumentHandler.prototype.handlePost = function(request, response) {
|
||||||
var key = '123';
|
var key = this.randomKey();
|
||||||
request.on('data', function(data) {
|
request.on('data', function(data) {
|
||||||
if (!DocumentHandler.documents[key]) {
|
if (!DocumentHandler.documents[key]) {
|
||||||
response.writeHead(200, { 'content-type': 'application/json' });
|
response.writeHead(200, { 'content-type': 'application/json' });
|
||||||
|
@ -42,6 +44,15 @@ DocumentHandler.prototype.handlePost = function(request, response) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO block modifying
|
// Generate a random key
|
||||||
|
// TODO make length configurable
|
||||||
|
DocumentHandler.prototype.randomKey = function() {
|
||||||
|
var text = '';
|
||||||
|
var keyspace = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||||
|
for (var i = 0; i < 6; i++) {
|
||||||
|
text += keyspace.charAt(Math.floor(Math.random() * keyspace.length));
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = DocumentHandler;
|
module.exports = DocumentHandler;
|
||||||
|
|
Loading…
Reference in a new issue