Browse Source

feat: show error when dont have access to file

Ahmad Kholid 3 years ago
parent
commit
a4d34f84e8

+ 3 - 1
src/background/index.js

@@ -193,7 +193,9 @@ message.on('get:file', (path) => {
       }
     };
     xhr.onerror = function () {
-      reject(new Error(xhr.statusText));
+      reject(
+        new Error(xhr.statusText || `Can't find a file with "${path}" path`)
+      );
     };
     xhr.open('GET', fileUrl);
     xhr.send();

+ 16 - 0
src/background/workflow-engine/blocks-handler/handler-interaction-block.js

@@ -1,7 +1,23 @@
 import { objectHasKey } from '@/utils/helper';
 import { getBlockConnection } from '../helper';
 
+async function checkAccess(blockName) {
+  if (blockName === 'upload-file') {
+    const hasFileAccess = await new Promise((resolve) =>
+      chrome.extension.isAllowedFileSchemeAccess(resolve)
+    );
+
+    if (hasFileAccess) return true;
+
+    throw new Error('no-file-access');
+  }
+
+  return true;
+}
+
 async function interactionHandler(block, { refData }) {
+  await checkAccess(block.name);
+
   const { executedBlockOnWeb, debugMode } = this.workflow.settings;
 
   const nextBlockId = getBlockConnection(block);

+ 2 - 1
src/locales/en/newtab.json

@@ -112,9 +112,10 @@
       "empty-spreadsheet-id": "Spreadsheet Id is empty",
       "invalid-loop-data": "Invalid data to loop through",
       "empty-workflow": "You must select a workflow first",
-      "empty-spreadsheet-range": "Spreadsheet range is empty",
       "active-tab-removed": "Workflow active tab is removed",
+      "empty-spreadsheet-range": "Spreadsheet range is empty",
       "stop-timeout": "Workflow is stopped because of timeout",
+      "no-file-access": "Automa doesn't have access to the file",
       "no-workflow": "Can't find workflow with \"{workflowId}\" ID",
       "element-not-found": "Can't find an element with \"{selector}\" selector.",
       "not-iframe": "Element with \"{selector}\" selector is not an Iframe element",