Browse Source

Fix file inputs being overwritten with strings.
Added force option in case we really need to overwrite

j433866 6 years ago
parent
commit
42cfed5fa8
2 changed files with 8 additions and 3 deletions
  1. 5 3
      src/web/waiters/InputWaiter.mjs
  2. 3 0
      src/web/workers/InputWorker.mjs

+ 5 - 3
src/web/waiters/InputWaiter.mjs

@@ -515,8 +515,9 @@ class InputWaiter {
      *
      *
      * @param {number} inputNum
      * @param {number} inputNum
      * @param {string | ArrayBuffer} value
      * @param {string | ArrayBuffer} value
+     * @param {boolean} [force=false] - If true, forces the value to be updated even if the type is different to the currently stored type
      */
      */
-    updateInputValue(inputNum, value) {
+    updateInputValue(inputNum, value, force=false) {
         let includeInput = false;
         let includeInput = false;
         const recipeStr = toBase64(value, "A-Za-z0-9+/"); // B64 alphabet with no padding
         const recipeStr = toBase64(value, "A-Za-z0-9+/"); // B64 alphabet with no padding
         if (recipeStr.length > 0 && recipeStr.length <= 68267) {
         if (recipeStr.length > 0 && recipeStr.length <= 68267) {
@@ -534,7 +535,8 @@ class InputWaiter {
             action: "updateInputValue",
             action: "updateInputValue",
             data: {
             data: {
                 inputNum: inputNum,
                 inputNum: inputNum,
-                value: value
+                value: value,
+                force: force
             }
             }
         }, transferable);
         }, transferable);
     }
     }
@@ -1025,7 +1027,7 @@ class InputWaiter {
         this.manager.highlighter.removeHighlights();
         this.manager.highlighter.removeHighlights();
         getSelection().removeAllRanges();
         getSelection().removeAllRanges();
 
 
-        this.updateInputValue(inputNum, "");
+        this.updateInputValue(inputNum, "", true);
 
 
         this.set({
         this.set({
             inputNum: inputNum,
             inputNum: inputNum,

+ 3 - 0
src/web/workers/InputWorker.mjs

@@ -546,10 +546,13 @@ self.updateInputProgress = function(inputData) {
  * @param {object} inputData
  * @param {object} inputData
  * @param {number} inputData.inputNum - The input that's having its value updated
  * @param {number} inputData.inputNum - The input that's having its value updated
  * @param {string | ArrayBuffer} inputData.value - The new value of the input
  * @param {string | ArrayBuffer} inputData.value - The new value of the input
+ * @param {boolean} inputData.force - If true, still updates the input value if the input type is different to the stored value
  */
  */
 self.updateInputValue = function(inputData) {
 self.updateInputValue = function(inputData) {
     const inputNum = inputData.inputNum;
     const inputNum = inputData.inputNum;
     if (inputNum < 1) return;
     if (inputNum < 1) return;
+    if (Object.prototype.hasOwnProperty.call(self.inputs[inputNum].data, "fileBuffer") &&
+    typeof inputData.value === "string" && !inputData.force) return;
     const value = inputData.value;
     const value = inputData.value;
     if (self.inputs[inputNum] !== undefined) {
     if (self.inputs[inputNum] !== undefined) {
         if (typeof value === "string") {
         if (typeof value === "string") {