From f5e3a251972b9f345b68628a5c4b3e8f72b8309f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sat, 14 Sep 2024 19:18:37 +0100 Subject: [PATCH] [wasm] fix: NCMFile & loader issue --- um_wasm/src/exports/ncm.rs | 8 +++++++- um_wasm_loader/build.js | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/um_wasm/src/exports/ncm.rs b/um_wasm/src/exports/ncm.rs index 031f577..4e41773 100644 --- a/um_wasm/src/exports/ncm.rs +++ b/um_wasm/src/exports/ncm.rs @@ -3,7 +3,7 @@ use umc_ncm::NetEaseCryptoError; use wasm_bindgen::prelude::wasm_bindgen; use wasm_bindgen::JsError; -/// QMC Footer. +/// NCMFile #[wasm_bindgen(js_name=NCMFile)] pub struct JsNCMFile { ncm: Option, @@ -11,6 +11,12 @@ pub struct JsNCMFile { #[wasm_bindgen(js_class=NCMFile)] impl JsNCMFile { + /// Create a NCMFile instance + #[wasm_bindgen(constructor)] + pub fn new() -> Result { + Ok(JsNCMFile { ncm: None }) + } + /// Open NCM file. /// If everything is ok, return `0`. /// diff --git a/um_wasm_loader/build.js b/um_wasm_loader/build.js index d689266..62e6e4d 100644 --- a/um_wasm_loader/build.js +++ b/um_wasm_loader/build.js @@ -92,6 +92,9 @@ async function main() { // Ask rollup to build bundles. await run(['pnpm', 'build:bundle']); await run(['pnpm', 'exec', 'prettier', '--ignore-path', '', '-w', 'dist/loader.d.ts']); + await replaceFileByRegex(path.join(wasmDistDir, 'loader.mjs'), [ + ['fetch(filepath)', 'fetch(new URL(filepath, import.meta.url))'], + ]); } main()