Skip to content

Commit

Permalink
pass through configuration from server
Browse files Browse the repository at this point in the history
  • Loading branch information
finnboeger committed May 2, 2020
1 parent e8ff46c commit fa7d632
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions client-data/tools/document/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
// File size as data url, approximately 1/3 larger than as bytestream
//TODO: internationalization
let size = image.src.toString().length;
if (size > 1048576) { //TODO: get correct size from config
if (size > Tools.server_config.MAX_DOCUMENT_SIZE) {
alert("File too large");
throw new Error("File too large");
}

if (Tools.svg.querySelectorAll("image").length > 5) { //TODO: get correct amount from config
if (Tools.svg.querySelectorAll("image").length > Tools.server_config.MAX_DOCUMENT_COUNT) {
alert("Too many documents exist already");
throw new Error("Too many documents exist already");
}
Expand Down
2 changes: 2 additions & 0 deletions server/client_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const config = require("./configuration");

/** Settings that should be handed through to the clients */
module.exports = {
"MAX_DOCUMENT_SIZE": config,MAX_DOCUMENT_SIZE,
"MAX_DOCUMENT_COUNT": config.MAX_DOCUMENT_COUNT,
"MAX_BOARD_SIZE": config.MAX_BOARD_SIZE,
"MAX_EMIT_COUNT": config.MAX_EMIT_COUNT,
"MAX_EMIT_COUNT_PERIOD": config.MAX_EMIT_COUNT_PERIOD,
Expand Down
5 changes: 3 additions & 2 deletions server/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ module.exports = {
MAX_BOARD_SIZE: parseInt(process.env['WBO_MAX_BOARD_SIZE']) || 65536,

/** Maximum size of uploaded documents default 1MB */
MAX_DOUMENT_SIZE: parseInt(process.env['WBO_MAX_DOCUMENT_SIZE']) || 1048576,
MAX_DOCUMENT_SIZE: parseInt(process.env['WBO_MAX_DOCUMENT_SIZE']) || 1048576,

/** Maximum number of documents allowed */
MAX_DOCUMENTS: parseInt(process.env['WBO_MAX_DOCUMENTS']) || 5,
MAX_DOCUMENT_COUNT: parseInt(process.env['WBO_MAX_DOCUMENT_COUNT']) || 5,

/** Maximum messages per user over the given time period before banning them */
MAX_EMIT_COUNT: parseInt(process.env['WBO_MAX_EMIT_COUNT']) || 128,

Expand Down
2 changes: 1 addition & 1 deletion server/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function socketConnection(socket) {
}
});

if (!message.data.size || message.data.size > config.MAX_DOUMENT_SIZE) {
if (!message.data.size || message.data.size > config.MAX_DOCUMENT_SIZE) {
console.warn("Received too large file");
return;
}
Expand Down

0 comments on commit fa7d632

Please sign in to comment.