From d4561fb5c2684dd12d6dc013945015daf3c38bc7 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 29 Sep 2023 09:05:49 -0700 Subject: [PATCH] Do not use full filename when FileLocator decides which asset to load Fixes https://github.com/google/mediapipe/issues/4819 PiperOrigin-RevId: 569506907 --- mediapipe/tasks/web/core/task_runner.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mediapipe/tasks/web/core/task_runner.ts b/mediapipe/tasks/web/core/task_runner.ts index 8b43b272..666b0104 100644 --- a/mediapipe/tasks/web/core/task_runner.ts +++ b/mediapipe/tasks/web/core/task_runner.ts @@ -52,13 +52,14 @@ export async function createTaskRunner( fileset: WasmFileset, options: TaskRunnerOptions): Promise { const fileLocator: FileLocator = { locateFile(file): string { - const wasm = fileset.wasmBinaryPath.toString(); - if (wasm.includes(file)) { - return wasm; - } - const asset = fileset.assetBinaryPath?.toString(); - if (asset?.includes(file)) { - return asset; + // We currently only use a single .wasm file and a single .data file (for + // the tasks that have to load assets). We need to revisit how we + // initialize the file locator if we ever need to differentiate between + // diffferent files. + if (file.endsWith('.wasm')) { + return fileset.wasmBinaryPath.toString(); + } else if (fileset.assetBinaryPath && file.endsWith('.data')) { + return fileset.assetBinaryPath.toString(); } return file; }