#I don't understand how to use PathResolver and AssetResolver

47 messages · Page 1 of 1 (latest)

wispy portal
#

How do you create them? Their methods all have an &self parameter, so I figured that you probably have to make an instance of them.

gloomy stag
#

you need to get them via asset_resolver() and path_resolver() from the App or AppHandle

wispy portal
#

ohhh

#

I have a text file with an image stored in base64 and I wanted to read the text. For some reason, I got the html of my frontend with this code:

let asset_resolver = app.asset_resolver();
let text = asset_resolver.get("assets/icon_base64.txt".into());
match text {
    Some(text) => {
        let bytes = text.bytes;
        let str = match String::from_utf8(bytes) {
            Ok(v) => v,
            Err(err) => panic!("Invalid UTF-8 sequence: {err:#?}"),
        };
        println!("result: {}", str);
    }
    None => println!("No text found"),
}
result: <!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<body style="margin: 0%;">
    <script type="module" src="/scripts/index.js" defer></script>
    <link rel="stylesheet" href="styles/style.css">
    <div id="main_div"
        style="position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);text-align: center;">
        <a id="progress_text" style="font-size: 4vw;"></a>
        <div id="border_div"
            style="margin-top:1.3vw; border:#FBF5F3; border-width: 1.8vh; border-style: solid; width: 70vw; height: 5vh;">
            <div id="progress_bar" style="background-color: #004FFF; width:0%; height:100%"></div>
        </div>
        <a class="error_text" id="error_text" style="margin-top: 1.3vw; display:block;"></a>
    </div>

</body>

</html>```
#

Btw, do you automatically get notifications or do I need to ping you in threads? @gloomy stag

#

I just realised what happened after removing the println!.

#

ssets/icon_base64.txt??

gloomy stag
wispy portal
#

nice

gloomy stag
# wispy portal `ssets/icon_base64.txt`??

oh yeah, i remember that. because assetresolver is actually used internally for serving your frontend it expects a / in front and always removes the first char without checking what specific char it is

wispy portal
#

what

#

bruh

#

that is a bit weird

gloomy stag
#

it really is

wispy portal
#

maybe a different error when it doesn't have / in front?

#

also since we're on the topic of these messages, is there any way to make it stop searching for favicon.ico?

gloomy stag
gloomy stag
wispy portal
#

ah

#

well that's sad

#

what if I name my icon favicon.ico?

#

I think it's called transparentcon.ico right now

gloomy stag
#

yeah that would "fix" it

wispy portal
#

it still can't find the asset

#

Am I supposed to specify an assets folder somewhere?

gloomy stag
#

the assetresolver server whatever is in your distDir, with the same directory structure

#

ohh, just noticed that it's inside your backend source

wispy portal
#

my distDir is ./ui

#

and my devPath is the same

#

I guess I could change distDir to ./assets

gloomy stag
gloomy stag
wispy portal
#

what if i just put the text in ui?

gloomy stag
wispy portal
#

nice

#

but it still doesn't work

#

hmmmmmmmmm

#

the specified path is /assets/icon_base64.txt

gloomy stag
#

and the file is in ui/assets/icon_base64.txt ?

wispy portal
#

yes

#

forget i said that, i'm an idiot

gloomy stag
#

okay kkushLUL

wispy portal