change asset resolver docs and name
This commit is contained in:
1 parent
6eba7e8641
commit
192fbffc51
3 files changed
+12
-3
No files matched your search
@@ -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(
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in new issue
Block a user