Browse Source

Merge pull request #6708 from nocodb/nc-fix/import-worker-issue

fix: Import worker issue
pull/6716/head
Pranav C 1 year ago committed by GitHub
parent
commit
a096d40b73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      packages/nc-gui/components/dlg/QuickImport.vue
  2. 1
      packages/nc-gui/package.json
  3. 24
      packages/nc-gui/utils/workerUtils.ts
  4. 7
      pnpm-lock.yaml

8
packages/nc-gui/components/dlg/QuickImport.vue

@ -149,10 +149,12 @@ const dialogShow = useVModel(rest, 'modelValue', emit)
if (isWorkerSupport) {
watch(
dialogShow,
(val) => {
async (val) => {
if (val) {
importWorker = initWorker(importWorkerUrl)
} else importWorker?.terminate()
importWorker = await initWorker(importWorkerUrl)
} else {
importWorker?.terminate()
}
},
{ immediate: true },
)

1
packages/nc-gui/package.json

@ -48,6 +48,7 @@
"@vueuse/integrations": "^10.2.1",
"ant-design-vue": "^3.2.11",
"chart.js": "^4.3.0",
"crossoriginworker": "^1.1.0",
"d3-scale": "^4.0.2",
"dagre": "^0.8.5",
"dayjs": "^1.11.9",

24
packages/nc-gui/utils/workerUtils.ts

@ -1,3 +1,5 @@
import getCrossOriginWorkerURL from 'crossoriginworker'
// Returns a blob:// URL which points
// to a javascript file which will call
// importScripts with the given URL
@ -6,18 +8,20 @@ export function getWorkerURL(url: string) {
return URL.createObjectURL(new Blob([content], { type: 'text/javascript' }))
}
export function initWorker(url: string) {
export async function initWorker(url: string) {
let worker: Worker | null = null
try {
if (/^https?:\/\/'/.test(url)) {
const worker_url = getWorkerURL(url)
worker = new Worker(worker_url)
URL.revokeObjectURL(worker_url)
} else {
worker = new Worker(url, {
type: 'module',
})
}
const workerURL = await getCrossOriginWorkerURL(url)
worker = new Worker(workerURL)
// if (/^https?:\/\/'/.test(url)) {
// // const worker_url = getWorkerURL(url)
// // worker = new Worker(worker_url)
// // URL.revokeObjectURL(worker_url)
// } else {
// worker = new Worker(url, {
// type: 'module',
// })
// }
} catch (e) {
console.error(e)
}

7
pnpm-lock.yaml

@ -63,6 +63,9 @@ importers:
chart.js:
specifier: ^4.3.0
version: 4.3.0
crossoriginworker:
specifier: ^1.1.0
version: 1.1.0
d3-scale:
specifier: ^4.0.2
version: 4.0.2
@ -11285,6 +11288,10 @@ packages:
which: 2.0.2
dev: true
/crossoriginworker@1.1.0:
resolution: {integrity: sha512-nNrgCCyA8Qel1qiZDg4qAQMpIhup0yVCQZh04uv0rktIyLaTszli8Mhhb5ZcoeCcnkEPIjf2L+lAJidmeprYWg==}
dev: false
/crypt@0.0.2:
resolution: {integrity: sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==}
dev: false

Loading…
Cancel
Save