mirror of
https://github.com/SunRed/haste-server.git
synced 2024-11-23 17:50:19 +01:00
Added support for haste maximum size
This commit is contained in:
parent
29a600fe87
commit
a9e29c2986
4 changed files with 13 additions and 1 deletions
2
TODO
2
TODO
|
@ -1,9 +1,9 @@
|
||||||
cache headers for static assets
|
cache headers for static assets
|
||||||
tests
|
tests
|
||||||
maximum size of a haste
|
|
||||||
fix any annoying visual quirks
|
fix any annoying visual quirks
|
||||||
add FAVICON
|
add FAVICON
|
||||||
cache static in memory
|
cache static in memory
|
||||||
|
add feedback for errors to UI - esp. too long
|
||||||
|
|
||||||
# shared version only
|
# shared version only
|
||||||
some way to do announcements easily (and use for ads)
|
some way to do announcements easily (and use for ads)
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
"keyLength": 6,
|
"keyLength": 6,
|
||||||
|
|
||||||
|
"maxLength": 400000,
|
||||||
|
|
||||||
"logging": [
|
"logging": [
|
||||||
{
|
{
|
||||||
"level": "verbose",
|
"level": "verbose",
|
||||||
|
|
|
@ -5,6 +5,7 @@ var winston = require('winston');
|
||||||
var DocumentHandler = function(options) {
|
var DocumentHandler = function(options) {
|
||||||
if (options) {
|
if (options) {
|
||||||
this.keyLength = options.keyLength || 10;
|
this.keyLength = options.keyLength || 10;
|
||||||
|
this.maxLength = options.maxLength; // none by default
|
||||||
this.store = options.store;
|
this.store = options.store;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -35,8 +36,15 @@ DocumentHandler.prototype.handlePost = function(request, response) {
|
||||||
response.writeHead(200, { 'content-type': 'application/json' });
|
response.writeHead(200, { 'content-type': 'application/json' });
|
||||||
}
|
}
|
||||||
buffer += data.toString();
|
buffer += data.toString();
|
||||||
|
if (_this.maxLength && buffer.length > _this.maxLength) {
|
||||||
|
_this.cancelled = true;
|
||||||
|
winston.warn('attempted to upload a document >maxLength', { maxLength: _this.maxLength });
|
||||||
|
response.writeHead(400, { 'content-type': 'application/json' });
|
||||||
|
response.end(JSON.stringify({ message: 'document exceeds maximum length' }));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
request.on('end', function(end) {
|
request.on('end', function(end) {
|
||||||
|
if (_this.cancelled) return;
|
||||||
_this.store.set(key, buffer, function(res) {
|
_this.store.set(key, buffer, function(res) {
|
||||||
if (res) {
|
if (res) {
|
||||||
winston.verbose('added document', { key: key });
|
winston.verbose('added document', { key: key });
|
||||||
|
@ -44,6 +52,7 @@ DocumentHandler.prototype.handlePost = function(request, response) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
winston.verbose('error adding document');
|
winston.verbose('error adding document');
|
||||||
|
response.writeHead(500, { 'content-type': 'application/json' });
|
||||||
response.end(JSON.stringify({ message: 'error adding document' }));
|
response.end(JSON.stringify({ message: 'error adding document' }));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -47,6 +47,7 @@ http.createServer(function(request, response) {
|
||||||
if (incoming.pathname.match(/^\/documents$/) && request.method == 'POST') {
|
if (incoming.pathname.match(/^\/documents$/) && request.method == 'POST') {
|
||||||
handler = new DocumentHandler({
|
handler = new DocumentHandler({
|
||||||
keyLength: config.keyLength,
|
keyLength: config.keyLength,
|
||||||
|
maxLength: config.maxLength,
|
||||||
store: preferredStore()
|
store: preferredStore()
|
||||||
});
|
});
|
||||||
return handler.handlePost(request, response);
|
return handler.handlePost(request, response);
|
||||||
|
|
Loading…
Reference in a new issue