Enables recursive asset compression and path preservation#7
Enables recursive asset compression and path preservation#7DaneSlattery wants to merge 9 commits into
Conversation
|
Tested with a folder structure like this: |
|
Your asset preparation code is a real benefit to serving http from embedded devices, seeing as the html can be encoded as part of firmware updates. If it was offboard on an SD card, you couldn't update the web portal OTA. I wonder how you feel about moving it into |
ivmarkov
left a comment
There was a problem hiding this comment.
I think this is mostly fine, but I suggest two changes - the first is the file_uri thing, especially the replace call. I don't think your current code would work OK on Windows, as it will preserve \ and we want this converted to `'/'.
The second change is that I don't see why scanning the assets_dir should be interleaved with file compression, hence I suggest visit_path where you currently have this interleaving visit_dir (which also unneccessarily uses a dyn callback but that's a detail).
| Ok(()) | ||
| } | ||
|
|
||
| fn visit_dirs(dir: &Path, cb: &dyn Fn(&DirEntry) -> PathBuf) -> anyhow::Result<Vec<PathBuf>> { |
There was a problem hiding this comment.
fn visit_files(path: &Path) -> anyhow::Result<Vec<PathBuf>> {
if path.is_file() {
Ok(vec![path.to_owned()])
} else {
let mut paths = Vec::new();
for entry in fs::read_dir(dir)? {
paths.extend(visit_paths(entry?.path())?);
}
Ok(paths)
}
}Once you have this, you can leave the current compress_file almost intact, and only change the code that derives the compressed file path, as it can no longer use output_dir.join(format!("{}.gz", file.file_name().to_str().unwrap())); but something just a tad more complicated, so that it preserves the relative file path to the assets dir into the output dir, and appends a ".gz" suffix.
There was a problem hiding this comment.
but something just a tad more complicated
I think this is the logic in compress_file, so this could work. I can't currently test this because I can't build it on my machine thanks to anymap :-( ,
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast
--> C:\Users\biopl\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\anymap-1.0.0-beta.2\src\any.rs:37:40
|
37 | unsafe { Box::from_raw(raw as *mut $t) }
There was a problem hiding this comment.
ok I fixed this with a patch, and upstreamed some stuff to yewdux-middleware
|
Any progress on the review ? |
Sorry for the delay. Will try to get back to this tmr! |
| opt-level = "z" | ||
|
|
||
| [workspace.dependencies] | ||
| yewdux-middleware = { git="https://github.com/DaneSlattery/yewdux-middleware.git" , branch="dms_anymap"} |
There was a problem hiding this comment.
Please use the just-released yewdux-middleware 0.4.0
| [workspace.dependencies] | ||
| yewdux-middleware = { git="https://github.com/DaneSlattery/yewdux-middleware.git" , branch="dms_anymap"} | ||
| yewdux = {version = "*",default-features = false} | ||
| yew={version = "0.22.0", default-features = false} |
There was a problem hiding this comment.
Nit: put spaces around "="
| yew={version = "0.22.0", default-features = false} | ||
| yew-router = { version = "0.19.0"} | ||
|
|
||
| [patch.crates-io] |
There was a problem hiding this comment.
Is this still necessary? I really hope not, or else how are we supposed to release this stuff? Please explain.
There was a problem hiding this comment.
This particular patch is due to:
intendednull/yewdux#88, which is solved in
intendednull/yewdux#89, but it seems the yewdux is unmaintained
There was a problem hiding this comment.
I'm not sure how it affects releasability
There was a problem hiding this comment.
looks like there is some movement there at least
There was a problem hiding this comment.
Ah I see, pretty impressive wielding of the copilot , but hopefully not needed
Restores original workspace Cargo.toml from before commit 3722eb7, then applies minimal change: yewdux version set to 0.12.0 and [patch.crates-io] section removed. Fixes: intendednull/yewdux#88 Co-authored-by: DaneSlattery <16350310+DaneSlattery@users.noreply.github.com>
…3722eb7 Revert accidental Cargo.toml overwrite and set yewdux = 0.12.0
|
bump |
Addresses #6