Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added document tool to upload images #42

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions client-data/tools/document/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,47 @@

// This isn't an HTML5 canvas, it's an old svg hack, (the code is _that_ old!)

var xlinkNS = "http://www.w3.org/1999/xlink";
var imgCount = 1;
const xlinkNS = "http://www.w3.org/1999/xlink";
let imgCount = 1;

function onstart() {
const fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = "image/*";
fileInput.click();
fileInput.addEventListener("change", () => {
finnboeger marked this conversation as resolved.
Show resolved Hide resolved
var reader = new FileReader();
const reader = new FileReader();
reader.readAsDataURL(fileInput.files[0]);

reader.onload = function (e) {
var image = new Image();
const image = new Image();
image.src = e.target.result;
image.onload = function () {

var uid = Tools.generateUID("doc"); // doc for document
console.log(image.src.toString().length);

var msg = {
// 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
finnboeger marked this conversation as resolved.
Show resolved Hide resolved
alert("File too large");
throw new Error("File too large");
}

if (Tools.svg.querySelectorAll("image").length > 5) { //TODO: get correct amount from config
alert("Too many documents exist already");
throw new Error("Too many documents exist already");
}

const msg = {
id: uid,
type:"doc",
type: "doc",
data: image.src,
size: image.src.toString().length,
w: this.width || 300,
h: this.height || 300,
x: (100+document.documentElement.scrollLeft)/Tools.scale+10*imgCount,
y: (100+document.documentElement.scrollTop)/Tools.scale + 10*imgCount
x: (100 + document.documentElement.scrollLeft) / Tools.scale + 10 * imgCount,
y: (100 + document.documentElement.scrollTop) / Tools.scale + 10 * imgCount
//fileType: fileInput.files[0].type
};
draw(msg);
Expand Down
6 changes: 6 additions & 0 deletions server/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ module.exports = {

/** Maximum value for any x or y on the board */
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,

/** Maximum number of documents allowed */
MAX_DOCUMENTS: parseInt(process.env['WBO_MAX_DOCUMENTS']) || 5,
};
26 changes: 25 additions & 1 deletion server/sockets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var iolib = require('socket.io')
, log = require("./log.js").log
, BoardData = require("./boardData.js").BoardData;
, BoardData = require("./boardData.js").BoardData
, config = require("./configuration");

var MAX_EMIT_COUNT = 64; // Maximum number of draw operations before getting banned
var MAX_EMIT_COUNT_PERIOD = 5000; // Duration (in ms) after which the emit count is reset
Expand Down Expand Up @@ -51,6 +52,9 @@ function socketConnection(socket) {
var board = await getBoard(name);
board.users.add(socket.id);
log('board joined', { 'board': board.name, 'users': board.users.size });

console.log(board);

return board;
}

Expand Down Expand Up @@ -96,6 +100,26 @@ function socketConnection(socket) {
return;
}

if (message.data.type === "doc") {
getBoard(boardName).then(boardData => {
let existingDocuments = 0;
for (key in boardData.board) {
if (boardData.board[key].type === "doc") {
existingDocuments += 1;
}
if (existingDocuments >= config.MAX_DOCUMENTS) {
console.warn("Received too many documents");
return;
}
}
finnboeger marked this conversation as resolved.
Show resolved Hide resolved
});

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

//Send data to all other users connected on the same board
socket.broadcast.to(boardName).emit('broadcast', data);

Expand Down