Skip to content

Commit 8d4dbcb

Browse files
committed
wasm error resolve
1 parent c77c09e commit 8d4dbcb

2 files changed

Lines changed: 39 additions & 20 deletions

File tree

crates/fula-client/src/client.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,24 +1014,6 @@ impl FulaClient {
10141014
}
10151015
}
10161016

1017-
/// Wasm version: no offline fallback infrastructure on browsers.
1018-
/// Delegate to the standard master fetch so call sites can use one
1019-
/// name across targets without `cfg` gates of their own.
1020-
#[cfg(target_arch = "wasm32")]
1021-
pub async fn get_object_with_offline_fallback_known_cid(
1022-
&self,
1023-
bucket: &str,
1024-
key: &str,
1025-
_cid_hint: &cid::Cid,
1026-
) -> Result<OfflineGetResult> {
1027-
let inner = self.get_object_with_metadata(bucket, key).await?;
1028-
Ok(OfflineGetResult {
1029-
inner,
1030-
source: ReadSource::Master,
1031-
freshness: ReadFreshness::Live,
1032-
})
1033-
}
1034-
10351017
/// Check if an object exists
10361018
#[instrument(skip(self))]
10371019
pub async fn object_exists(&self, bucket: &str, key: &str) -> Result<bool> {

crates/fula-client/src/encryption.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,10 +3900,17 @@ impl EncryptedClient {
39003900
// server is reachable. Pages that have never been flushed
39013901
// (`page_ref.etag = None`) fall back to the no-hint wrapper;
39023902
// those pages have no on-IPFS bytes to fetch anyway.
3903-
let cid_hint = page_ref
3903+
//
3904+
// Native-only: the `cid` crate is gated to non-wasm targets
3905+
// and the CID-hint method itself is too. On wasm we just
3906+
// route through the no-hint wrapper, which already handles
3907+
// master-up (the only fetch path supported on wasm anyway).
3908+
#[cfg(not(target_arch = "wasm32"))]
3909+
let cid_hint: Option<cid::Cid> = page_ref
39043910
.etag
39053911
.as_deref()
39063912
.and_then(|s| s.parse::<cid::Cid>().ok());
3913+
#[cfg(not(target_arch = "wasm32"))]
39073914
let blob = match cid_hint {
39083915
Some(cid) => self
39093916
.inner
@@ -3922,6 +3929,18 @@ impl EncryptedClient {
39223929
page_id, bucket, e
39233930
))
39243931
})?;
3932+
#[cfg(target_arch = "wasm32")]
3933+
let blob = self
3934+
.inner
3935+
.get_object_with_offline_fallback(bucket, &page_key)
3936+
.await
3937+
.map(|r| r.inner.data)
3938+
.map_err(|e| {
3939+
ClientError::DownloadFailed(format!(
3940+
"failed to fetch manifest page {} for bucket {}: {}",
3941+
page_id, bucket, e
3942+
))
3943+
})?;
39253944
let envelope = EncryptedManifestPage::from_bytes(&blob)
39263945
.map_err(ClientError::Encryption)?;
39273946
if envelope.page_id != *page_id {
@@ -3978,7 +3997,14 @@ impl EncryptedClient {
39783997
// CID-hint variant so a fresh device with no KEY_TO_CID
39793998
// warm-cache mapping can still race the gateway pool. The
39803999
// master-up path is identical regardless of hint.
3981-
let cid_hint = expected_etag.and_then(|s| s.parse::<cid::Cid>().ok());
4000+
//
4001+
// Native-only: `cid` crate + the CID-hint method are gated to
4002+
// non-wasm targets. wasm builds keep the no-hint wrapper
4003+
// (master-only path).
4004+
#[cfg(not(target_arch = "wasm32"))]
4005+
let cid_hint: Option<cid::Cid> =
4006+
expected_etag.and_then(|s| s.parse::<cid::Cid>().ok());
4007+
#[cfg(not(target_arch = "wasm32"))]
39824008
let blob = match cid_hint {
39834009
Some(cid) => match self
39844010
.inner
@@ -4001,6 +4027,17 @@ impl EncryptedClient {
40014027
Err(e) => return Err(e),
40024028
},
40034029
};
4030+
#[cfg(target_arch = "wasm32")]
4031+
let blob = match self
4032+
.inner
4033+
.get_object_with_offline_fallback(bucket, &key)
4034+
.await
4035+
.map(|r| r.inner.data)
4036+
{
4037+
Ok(b) => b,
4038+
Err(e) if e.is_not_found() => return Ok(None),
4039+
Err(e) => return Err(e),
4040+
};
40044041
// `get_object` discards the HEAD ETag so we cannot cross-check
40054042
// `expected_etag` here directly; it stays threaded for future refactors
40064043
// that expose the GET ETag on the read path. `expected_seq` is the

0 commit comments

Comments
 (0)