Index: lams_build/conf/whiteboard/scripts/s_whiteboard.js =================================================================== diff -u -r612dedddab7ffe856fc5cb1626a0f1db55b9cf1d -r77af7934c1b60274b5d2b534735179d56ea9b23b --- lams_build/conf/whiteboard/scripts/s_whiteboard.js (.../s_whiteboard.js) (revision 612dedddab7ffe856fc5cb1626a0f1db55b9cf1d) +++ lams_build/conf/whiteboard/scripts/s_whiteboard.js (.../s_whiteboard.js) (revision 77af7934c1b60274b5d2b534735179d56ea9b23b) @@ -159,12 +159,41 @@ savedBoards[targetWid] = sourceData.slice(); this.saveToDB(targetWid); }, - saveData: function(wid, data) { + saveData: function(wid, data, processEmbeddedImages) { const existingData = this.loadStoredData(wid); if (existingData.length > 0 || !data) { return; } - savedBoards[wid] = JSON.parse(data); + let savedBoard = JSON.parse(data); + + // importing LAMS content which has base64 images embedded + if (processEmbeddedImages) { + savedBoard.forEach(function(entry) { + // check if it is an embedded image or one with absolute URL + if (entry.t !== "addImgBG" || !entry.url.startsWith("/uploads/") || !entry.imageData) { + return true; + } + + // if the file already exists on the servrer, do nothing + const filePath = "./public" + entry.url; + if (fs.existsSync(filePath)) { + return true; + } + + // create a dir for the given output path + fs.mkdirSync(filePath.substring(0, filePath.lastIndexOf("/")), { + // this option also mutes an error if path exists + recursive : true + }); + + // write out data to file + fs.writeFileSync(filePath, entry.imageData, "base64"); + + // clean up + delete entry.imageData; + }); + } + savedBoards[wid] = savedBoard; this.saveToDB(wid); } }; Index: lams_build/conf/whiteboard/scripts/server-backend.js =================================================================== diff -u -rcf53a39fbd08dd3125cceba14221ac809ae6df13 -r77af7934c1b60274b5d2b534735179d56ea9b23b --- lams_build/conf/whiteboard/scripts/server-backend.js (.../server-backend.js) (revision cf53a39fbd08dd3125cceba14221ac809ae6df13) +++ lams_build/conf/whiteboard/scripts/server-backend.js (.../server-backend.js) (revision 77af7934c1b60274b5d2b534735179d56ea9b23b) @@ -63,13 +63,28 @@ const wid = req["query"]["wid"]; const at = req["query"]["at"]; //accesstoken const targetWid = req["query"]["targetWid"]; + const embedImages = req["query"]["embedImages"]; // if targetWid is present, hash generation is based on combined wids if (accessToken === "" || hashAccessToken(wid + (targetWid || "")) == at) { const widForData = ReadOnlyBackendService.isReadOnly(wid) ? ReadOnlyBackendService.getIdFromReadOnlyId(wid) : wid; - const ret = s_whiteboard.loadStoredData(widForData); + let ret = s_whiteboard.loadStoredData(widForData); + + if (embedImages) { + // exporting LAMS content: save image data directly in JSON + ret = ret.slice(); + ret.forEach(function(entry){ + if (entry.t !== "addImgBG" || !entry.url.startsWith("/uploads/")) { + return true; + } + const filePath = "./public" + entry.url; + const contents = fs.readFileSync(filePath, {encoding: 'base64'}); + entry.imageData = contents; + }); + } + res.send(ret); res.end(); } else { @@ -110,7 +125,7 @@ form.on("end", function () { if (accessToken === "" || hashAccessToken(formData["fields"]["wid"]) == formData["fields"]["at"]) { - s_whiteboard.saveData(formData["fields"]["wid"], formData["fields"]["content"]); + s_whiteboard.saveData(formData["fields"]["wid"], formData["fields"]["content"], true); res.end(); } else { res.status(401); //Unauthorized Index: lams_tool_whiteboard/src/java/org/lamsfoundation/lams/tool/whiteboard/service/WhiteboardService.java =================================================================== diff -u -r7cc3bf0a1c503019da5c957de4803dcb54c431ee -r77af7934c1b60274b5d2b534735179d56ea9b23b --- lams_tool_whiteboard/src/java/org/lamsfoundation/lams/tool/whiteboard/service/WhiteboardService.java (.../WhiteboardService.java) (revision 7cc3bf0a1c503019da5c957de4803dcb54c431ee) +++ lams_tool_whiteboard/src/java/org/lamsfoundation/lams/tool/whiteboard/service/WhiteboardService.java (.../WhiteboardService.java) (revision 77af7934c1b60274b5d2b534735179d56ea9b23b) @@ -627,9 +627,10 @@ if (whiteboardAccessToken != null) { parameters.append("&at=").append(whiteboardAccessToken); } - parameters.append("&content=").append(content); try { + parameters.append("&content=").append(URLEncoder.encode(content, FileUtil.ENCODING_UTF_8)); + HttpURLConnection connection = HttpUrlConnectionUtil.getConnection(url.toString()); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); @@ -657,8 +658,8 @@ } // using Whiteboard API from https://cloud13.de/testwhiteboard/apidoc/index.html String whiteboardServerUrl = getWhiteboardServerUrl(); - StringBuilder url = new StringBuilder().append(whiteboardServerUrl).append("/api/loadwhiteboard?wid=") - .append(wid); + StringBuilder url = new StringBuilder().append(whiteboardServerUrl) + .append("/api/loadwhiteboard?embedImages=true&wid=").append(wid); String whiteboardAccessToken = getWhiteboardAccessTokenHash(wid, null); if (whiteboardAccessToken != null) { url.append("&at=").append(whiteboardAccessToken); @@ -796,6 +797,8 @@ if (StringUtils.isNotBlank(toolContentObj.getExportContent())) { uploadWhiteboardContent(toolContentId.toString(), toolContentObj.getExportContent()); + // clean up + toolContentObj.setExportContent(null); } whiteboardDao.insertOrUpdate(toolContentObj);