Skip to content

Commit

Permalink
Merge pull request #111 from Stremio/fix/wasm-bindgen-version
Browse files Browse the repository at this point in the history
fix: downgrade wasm bindgen to 0.2.78
  • Loading branch information
elpiel authored May 27, 2024
2 parents 4205f4c + f0edb33 commit 1de151a
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: actions/checkout@v4

- name: Rust setup
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@1.77
with:
components: rustfmt, clippy
targets: wasm32-unknown-unknown
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
registry-url: https://registry.npmjs.org/

- name: Rust setup
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@1.77
with:
targets: wasm32-unknown-unknown

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

# For releasing we always use stable
- name: Rust setup
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@1.77
with:
targets: wasm32-unknown-unknown
- uses: taiki-e/install-action@v2
Expand Down
47 changes: 23 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enclose = "1.1.*"
itertools = "0.10.*"
boolinator = "2.4.*"
Inflector = "0.11.*"
wasm-bindgen = { version = "=0.2.92", features = ["serde-serialize"] }
wasm-bindgen = { version = "=0.2.78", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4"
gloo-utils = { version = "0.2", features = ["serde"] }

Expand Down
6 changes: 6 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[toolchain]
# 1.78 introduces a check which fails on the older
# version of wasm-bindgen, while the newest wasm-bindgen
# introduces an unknown panic when transpiled using
# wasm2js
channel = "1.77"
71 changes: 40 additions & 31 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ lazy_static! {
static ref VISIT_ID: String = hex::encode(WebEnv::random_buffer(10));
static ref ANALYTICS: Analytics<WebEnv> = Default::default();
static ref PLAYER_REGEX: Regex =
Regex::new(r"^/player/([^/]*)(?:/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*))?$").unwrap();
Regex::new(r"^/player/([^/]*)(?:/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*))?$")
.expect("Player Regex failed to build");
}

#[derive(Serialize)]
Expand Down Expand Up @@ -274,7 +275,8 @@ impl Env for WebEnv {
let value = String::from_utf8_lossy(value.as_bytes()).into_owned();
headers.entry(key).or_insert_with(Vec::new).push(value);
}
<JsValue as JsValueSerdeExt>::from_serde(&headers).unwrap()
<JsValue as JsValueSerdeExt>::from_serde(&headers)
.expect("WebEnv::fetch: JsValue from Headers failed to be built")
};
let body = match serde_json::to_string(&body) {
Ok(ref body) if body != "null" && parts.method != Method::GET => {
Expand All @@ -301,7 +303,9 @@ impl Env for WebEnv {
)
})?;

let resp = resp.dyn_into::<web_sys::Response>().unwrap();
let resp = resp
.dyn_into::<web_sys::Response>()
.expect("WebEnv::fetch: Response into web_sys::Response failed to be built");
// status check and JSON extraction from response.
let resp = if resp.status() != 200 {
return Err(EnvError::Fetch(format!(
Expand All @@ -311,26 +315,29 @@ impl Env for WebEnv {
} else {
// Response.json() to JSON::Stringify

JsFuture::from(resp.text().unwrap())
.map_err(|error| {
JsFuture::from(
resp.text()
.expect("WebEnv::fetch: Response text failed to be retrieved"),
)
.map_err(|error| {
EnvError::Fetch(
error
.dyn_into::<js_sys::Error>()
.map(|error| String::from(error.message()))
.unwrap_or_else(|_| UNKNOWN_ERROR.to_owned()),
)
})
.await
.and_then(|js_value| {
js_value.dyn_into::<js_sys::JsString>().map_err(|error| {
EnvError::Fetch(
error
.dyn_into::<js_sys::Error>()
.map(|error| String::from(error.message()))
.unwrap_or_else(|_| UNKNOWN_ERROR.to_owned()),
)
})
.await
.and_then(|js_value| {
js_value.dyn_into::<js_sys::JsString>().map_err(|error| {
EnvError::Fetch(
error
.dyn_into::<js_sys::Error>()
.map(|error| String::from(error.message()))
.unwrap_or_else(|_| UNKNOWN_ERROR.to_owned()),
)
})
})?
})?
};

response_deserialize(resp)
Expand Down Expand Up @@ -444,7 +451,7 @@ impl Env for WebEnv {
visit_id: VISIT_ID.to_owned(),
path: sanitize_location_path(path),
})
.unwrap()
.expect("AnalyticsContext to JSON")
}

#[cfg(debug_assertions)]
Expand All @@ -462,20 +469,22 @@ fn sanitize_location_path(path: &str) -> String {
.unwrap_or_default();
let path = match PLAYER_REGEX.captures(url.path()) {
Some(captures) => {
if captures.get(3).is_some()
&& captures.get(4).is_some()
&& captures.get(5).is_some()
&& captures.get(6).is_some()
{
format!(
"/player/***/***/{}/{}/{}/{}",
captures.get(3).unwrap().as_str(),
captures.get(4).unwrap().as_str(),
captures.get(5).unwrap().as_str(),
captures.get(6).unwrap().as_str(),
)
} else {
"/player/***".to_owned()
match (
captures.get(3),
captures.get(4),
captures.get(5),
captures.get(6),
) {
(Some(match_3), Some(match_4), Some(match_5), Some(match_6)) => {
format!(
"/player/***/***/{cap_3}/{cap_4}/{cap_5}/{cap_6}",
cap_3 = match_3.as_str(),
cap_4 = match_4.as_str(),
cap_5 = match_5.as_str(),
cap_6 = match_6.as_str(),
)
}
_ => "/player/***".to_owned(),
}
}
_ => url.path().to_owned(),
Expand Down
8 changes: 4 additions & 4 deletions src/model/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ impl WebModel {
pub fn get_state(&self, field: &WebModelField) -> JsValue {
match field {
WebModelField::Ctx => serialize_ctx(&self.ctx),
WebModelField::AuthLink => {
<JsValue as JsValueSerdeExt>::from_serde(&self.auth_link).unwrap()
}
WebModelField::AuthLink => <JsValue as JsValueSerdeExt>::from_serde(&self.auth_link)
.expect("JsValue from AuthLink"),
WebModelField::DataExport => serialize_data_export(&self.data_export),
WebModelField::ContinueWatchingPreview => serialize_continue_watching_preview(
&self.continue_watching_preview,
Expand Down Expand Up @@ -158,7 +157,8 @@ impl WebModel {
WebModelField::RemoteAddons => serialize_remote_addons(&self.remote_addons, &self.ctx),
WebModelField::InstalledAddons => serialize_installed_addons(&self.installed_addons),
WebModelField::AddonDetails => {
<JsValue as JsValueSerdeExt>::from_serde(&self.addon_details).unwrap()
<JsValue as JsValueSerdeExt>::from_serde(&self.addon_details)
.expect("JsValue from AddonDetails")
}
WebModelField::StreamingServer => serialize_streaming_server(&self.streaming_server),
WebModelField::Player => {
Expand Down
2 changes: 1 addition & 1 deletion src/model/serialize_catalogs_with_extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ pub fn serialize_catalogs_with_extra(
)
.collect::<Vec<_>>(),
})
.unwrap()
.expect("JsValue from model::CatalogsWithExtra")
}
2 changes: 1 addition & 1 deletion src/model/serialize_continue_watching_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn serialize_continue_watching_preview(
streaming_server_url,
settings,
)))
.unwrap()
.expect("JsValue from model::ContinueWatchingPreview")
}

mod model {
Expand Down
2 changes: 1 addition & 1 deletion src/model/serialize_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use wasm_bindgen::JsValue;
use stremio_core::models::ctx::Ctx;

pub fn serialize_ctx(ctx: &Ctx) -> JsValue {
<JsValue as JsValueSerdeExt>::from_serde(&model::Ctx::from(ctx)).unwrap()
<JsValue as JsValueSerdeExt>::from_serde(&model::Ctx::from(ctx)).expect("JsValue from Ctx")
}

mod model {
Expand Down
2 changes: 1 addition & 1 deletion src/model/serialize_data_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ pub fn serialize_data_export(data_export: &DataExport) -> JsValue {
.as_ref()
.map(|(_auth_key, loadable)| loadable),
})
.unwrap()
.expect("JsValue from model::DataExport")
}
7 changes: 5 additions & 2 deletions src/model/serialize_discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ pub fn serialize_discover(
next_page: discover.selectable.next_page.is_some(),
},
catalog: (!discover.catalog.is_empty()).as_option().map(|_| {
let first_page = discover.catalog.first().unwrap();
let first_page = discover
.catalog
.first()
.expect("discover catalog first page");
model::ResourceLoadable {
content: match &first_page.content {
Some(Loadable::Ready(_)) => Loadable::Ready(
Expand Down Expand Up @@ -228,5 +231,5 @@ pub fn serialize_discover(
}
}),
})
.unwrap()
.expect("JsValue from Discover model::CatalogWithFilters")
}
2 changes: 1 addition & 1 deletion src/model/serialize_installed_addons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ pub fn serialize_installed_addons(installed_addons: &InstalledAddonsWithFilters)
})
.collect(),
})
.unwrap()
.expect("JsValue from model::InstalledAddonsWithFilters")
}
2 changes: 1 addition & 1 deletion src/model/serialize_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ pub fn serialize_library<F>(
})
.collect(),
})
.unwrap()
.expect("JsValue from model::LibraryWithFilters")
}
2 changes: 1 addition & 1 deletion src/model/serialize_local_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ pub fn serialize_local_search(local_search: &LocalSearch) -> JsValue {
.unique_by(|i| i.query)
.collect(),
})
.unwrap()
.expect("JsValue from model::LocalSearch")
}
2 changes: 1 addition & 1 deletion src/model/serialize_meta_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,5 +375,5 @@ pub fn serialize_meta_details(
.unwrap_or_else(|| meta_item.preview.name.to_owned())
}),
})
.unwrap()
.expect("JsValue from model::MetaDetails")
}
2 changes: 1 addition & 1 deletion src/model/serialize_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,5 @@ pub fn serialize_player(player: &Player, ctx: &Ctx, streaming_server: &Streaming
},
}),
})
.unwrap()
.expect("JsValue from model::Player")
}
Loading

0 comments on commit 1de151a

Please sign in to comment.