From 192fbffc516d5e54dedebd5c537c652551529948 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Mon, 30 Jun 2025 16:31:25 -0700 Subject: [PATCH] change asset resolver docs and name --- packages/asset-resolver/src/lib.rs | 11 ++++++++++- packages/desktop/src/protocol.rs | 2 +- packages/native/src/assets.rs | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/asset-resolver/src/lib.rs b/packages/asset-resolver/src/lib.rs index 47225fbff..a5bc28250 100644 --- a/packages/asset-resolver/src/lib.rs +++ b/packages/asset-resolver/src/lib.rs @@ -14,7 +14,16 @@ pub enum AssetServeError { ResponseError(#[from] http::Error), } -pub fn serve_asset_from_raw_path(path: &str) -> Result>, AssetServeError> { +/// Serve an asset from the filesystem or a custom asset handler. +/// +/// This method properly accesses the asset directory based on the platform and serves the asset +/// wrapped in an HTTP response. +/// +/// Platform specifics: +/// - On the web, this returns AssetServerError since there's no filesystem access. Use `fetch` instead. +/// - On Android, it attempts to load assets using the Android AssetManager. +/// - On other platforms, it serves assets from the filesystem. +pub fn serve_asset(path: &str) -> Result>, AssetServeError> { // If the user provided a custom asset handler, then call it and return the response if the request was handled. // The path is the first part of the URI, so we need to trim the leading slash. let mut uri_path = PathBuf::from( diff --git a/packages/desktop/src/protocol.rs b/packages/desktop/src/protocol.rs index b694bc1e6..ca14e02ae 100644 --- a/packages/desktop/src/protocol.rs +++ b/packages/desktop/src/protocol.rs @@ -67,7 +67,7 @@ pub(super) fn desktop_handler( } } - match dioxus_asset_resolver::serve_asset_from_raw_path(request.uri().path()) { + match dioxus_asset_resolver::serve_asset(request.uri().path()) { Ok(res) => responder.respond(res), Err(_e) => responder.respond( Response::builder() diff --git a/packages/native/src/assets.rs b/packages/native/src/assets.rs index cde085662..3e1aae1fe 100644 --- a/packages/native/src/assets.rs +++ b/packages/native/src/assets.rs @@ -33,7 +33,7 @@ impl NetProvider for DioxusNativeNetProvider { handler: blitz_traits::net::BoxedHandler, ) { if request.url.scheme() == "dioxus" { - match dioxus_asset_resolver::serve_asset_from_raw_path(request.url.path()) { + match dioxus_asset_resolver::serve_asset(request.url.path()) { Ok(res) => { tracing::trace!("fetching asset from file system success {request:#?}"); handler.bytes(doc_id, res.into_body().into(), self.callback.clone())