Quellcode durchsuchen

change asset resolver docs and name

Jonathan Kelley vor 2 Tagen
Ursprung
Commit
192fbffc51

+ 10 - 1
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<Response<Vec<u8>>, 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<Response<Vec<u8>>, 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(

+ 1 - 1
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()

+ 1 - 1
packages/native/src/assets.rs

@@ -33,7 +33,7 @@ impl NetProvider<Resource> for DioxusNativeNetProvider {
         handler: blitz_traits::net::BoxedHandler<Resource>,
     ) {
         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())