|
@@ -1,8 +1,11 @@
|
|
|
+import browser from 'webextension-polyfill';
|
|
|
import { getBlockConnection } from '../helper';
|
|
|
-import dataExporter from '@/utils/data-exporter';
|
|
|
+import { default as dataExporter, files } from '@/utils/data-exporter';
|
|
|
|
|
|
-function exportData({ data, outputs }) {
|
|
|
- return new Promise((resolve) => {
|
|
|
+async function exportData({ data, outputs }) {
|
|
|
+ const nextBlockId = getBlockConnection({ outputs });
|
|
|
+
|
|
|
+ try {
|
|
|
const dataToExport = data.dataToExport || 'data-columns';
|
|
|
let payload = this.referenceData.table;
|
|
|
|
|
@@ -10,13 +13,43 @@ function exportData({ data, outputs }) {
|
|
|
payload = this.referenceData.googleSheets[data.refKey] || [];
|
|
|
}
|
|
|
|
|
|
- dataExporter(payload, data);
|
|
|
+ const hasDownloadAccess = await browser.permissions.contains({
|
|
|
+ permissions: ['downloads'],
|
|
|
+ });
|
|
|
+ const blobUrl = dataExporter(payload, {
|
|
|
+ ...data,
|
|
|
+ returnUrl: hasDownloadAccess,
|
|
|
+ });
|
|
|
+
|
|
|
+ if (hasDownloadAccess) {
|
|
|
+ const filename = `${data.name}${files[data.type].ext}`;
|
|
|
+ const blobId = blobUrl.replace('blob:chrome-extension://', '');
|
|
|
+ const filesname =
|
|
|
+ JSON.parse(sessionStorage.getItem('export-filesname')) || {};
|
|
|
+
|
|
|
+ const options = {
|
|
|
+ filename,
|
|
|
+ conflictAction: data.onConflict || 'uniquify',
|
|
|
+ };
|
|
|
|
|
|
- resolve({
|
|
|
+ filesname[blobId] = options;
|
|
|
+ sessionStorage.setItem('export-filesname', JSON.stringify(filesname));
|
|
|
+
|
|
|
+ await browser.downloads.download({
|
|
|
+ ...options,
|
|
|
+ url: blobUrl,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
data: '',
|
|
|
- nextBlockId: getBlockConnection({ outputs }),
|
|
|
- });
|
|
|
- });
|
|
|
+ nextBlockId,
|
|
|
+ };
|
|
|
+ } catch (error) {
|
|
|
+ error.nextBlockId = nextBlockId;
|
|
|
+
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export default exportData;
|