From 66b3d5c5f2bf9c5c0d99a740dd1b4fc07c80dbe0 Mon Sep 17 00:00:00 2001 From: Pierre-Henri Date: Sun, 21 Apr 2024 14:59:28 +0200 Subject: [PATCH] compatibility on worker resolution --- src/lib/file-id/FileIDComputerWorker.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/file-id/FileIDComputerWorker.ts b/src/lib/file-id/FileIDComputerWorker.ts index 1de4192..0ec6ce4 100644 --- a/src/lib/file-id/FileIDComputerWorker.ts +++ b/src/lib/file-id/FileIDComputerWorker.ts @@ -1,21 +1,21 @@ import {Piscina} from "piscina"; import {CID_ALGORITHM_NAMES} from "../hash-compute/MultiHashData"; -import {FileIDComputerInterface} from "@root/file-id/FileIDComputerInterface"; - -// Construct the URL for the current module -let distFolder = import.meta.dirname; -distFolder = distFolder.replace('src', 'dist'); -distFolder = distFolder + "/worker.js"; -const workerUrl = new URL(distFolder).href; export class FileIDComputerWorker{ private piscina: Piscina; constructor(workerPath?:string) { + if(!workerPath) { + // Construct the URL for the current module + let distFolder = import.meta.dirname; + distFolder = distFolder.replace('src', 'dist'); + distFolder = distFolder + "/worker.js"; + workerPath = new URL(distFolder,"file://").href; + } this.piscina = new Piscina({ maxThreads: 4, //filename: new URL('./ShaComputeWorker.ts', import.meta.url).href - filename: workerPath || process.env.WORKER_URL || workerUrl + filename: workerPath }); }