Skip to content

Commit

Permalink
handle spaces in image filenames
Browse files Browse the repository at this point in the history
fix no images shouldn't cause panic
  • Loading branch information
bbirchnz committed Dec 2, 2023
1 parent 7712ee4 commit a478e60
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ chrono = "0.4.24"
directories = "5.0.1"
itertools = "0.10.5"
copypasta = "0.10.0"
urlencoding = "2.1.3"
5 changes: 4 additions & 1 deletion ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ fn main() {
// remove leading '/' from path
let requested_image = req.uri().path().strip_prefix('/').unwrap();

// remove any url encoding (spaces etc)
let decoded = urlencoding::decode(requested_image).expect("UTF-8");

// now see if we've got the image requested:
if let Some(v) = image_vec.borrow().as_ref() {
if let Some(image) = v.iter().find(|bd| bd.name == requested_image) {
if let Some(image) = v.iter().find(|bd| bd.name == decoded) {
let response = Response::builder()
.header("Content-Type", "image/png")
.header("Content-Length", image.data.len().to_string())
Expand Down
10 changes: 9 additions & 1 deletion ui/src/rsx/image_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ pub struct ImageEditProps {
}

pub fn image_edit(cx: Scope<ImageEditProps>) -> Element {
let item_from_props = BinItem::from_selectable(&cx.props.item).unwrap();
let binitem_from_props = BinItem::from_selectable(&cx.props.item);

if binitem_from_props.is_none() {
return cx.render(rsx! {
"Nothing to edit"
});
}

let item_from_props = binitem_from_props.unwrap();
let item_state = use_state(cx, || item_from_props.to_owned());
let orig_name = use_state(cx, || item_state.get().name.to_owned());

Expand Down

0 comments on commit a478e60

Please sign in to comment.