feat: restored image upload

* only use readonly id when storing image to prevent leaking of the editable id
This commit is contained in:
Florent Chehab
2020-05-12 21:55:43 +02:00
parent 14e1ee5391
commit 2c2c104bbf
3 changed files with 60 additions and 31 deletions

View File

@@ -706,7 +706,7 @@ function initWhiteboard() {
);
function uploadImgAndAddToWhiteboard(base64data) {
var date = +new Date();
const date = +new Date();
$.ajax({
type: "POST",
url: document.URL.substr(0, document.URL.lastIndexOf("/")) + "/api/upload",
@@ -717,9 +717,11 @@ function initWhiteboard() {
at: accessToken,
},
success: function (msg) {
var filename = whiteboardId + "_" + date + ".png";
const { correspondingReadOnlyWid } = ConfigService;
const filename = `${correspondingReadOnlyWid}_${date}.png`;
const rootUrl = document.URL.substr(0, document.URL.lastIndexOf("/"));
whiteboard.addImgToCanvasByUrl(
document.URL.substr(0, document.URL.lastIndexOf("/")) + "/uploads/" + filename
`${rootUrl}/uploads/${correspondingReadOnlyWid}/${filename}`
); //Add image to canvas
console.log("Image uploaded!");
},

View File

@@ -12,6 +12,23 @@ class ConfigService {
return this.#configFromServer;
}
/**
* Associated read-only id for this whiteboad
* @type {string}
*/
#correspondingReadOnlyWid = "";
get correspondingReadOnlyWid() {
return this.#correspondingReadOnlyWid;
}
/**
* @type {boolean}
*/
#isReadOnly = true;
get isReadOnly() {
return this.#isReadOnly;
}
/**
* @type {{displayInfo: boolean, setReadOnly: boolean}}
* @readonly
@@ -97,6 +114,12 @@ class ConfigService {
this.#backgroundGridImage = backgroundGridImage;
this.#refreshInfoInterval = 1000 / performance.refreshInfoFreq;
const { whiteboardSpecific } = configFromServer;
const { correspondingReadOnlyWid, isReadOnly } = whiteboardSpecific;
this.#correspondingReadOnlyWid = correspondingReadOnlyWid;
this.#isReadOnly = isReadOnly;
console.log("Whiteboard config from server:", configFromServer, "parsed:", this);
}