Skip to content

Commit 5adb876

Browse files
committed
fix some lints from latest commit
1 parent 965fe1e commit 5adb876

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

pad/editor/src/backend.rs

+44-39
Original file line numberDiff line numberDiff line change
@@ -473,64 +473,69 @@ impl SysBackend for WebBackend {
473473
Some(res.clone())
474474
} else if original_url.contains("github.com") && url.ends_with("/lib.ua") {
475475
logging::log!("Fetching github repo: {url}");
476-
mark_working(&original_url);
476+
mark_working(original_url);
477477
let original_url = original_url.to_string();
478478

479479
spawn_local(async move {
480-
let tree_url = format!("https://api.github.com/repos/{repo_owner}/{repo_name}/git/trees/main?recursive=1");
481-
let tree_res = fetch(&tree_url).await;
482-
483-
if let Err(_) = tree_res {
484-
cache_url(&url, tree_res);
485-
unmark_working(&original_url);
486-
return;
487-
} else {
488-
let tree = tree_res.unwrap();
489-
let tree: serde_json::Value = serde_json::from_str(&tree).unwrap();
490-
let tree = tree.get("tree").unwrap().as_array().unwrap();
491-
let paths = tree
492-
.iter()
493-
.filter_map(|entry| {
494-
let path = entry.get("path")?.as_str()?;
495-
if path.ends_with(".ua") {
496-
Some(path.to_string())
497-
} else {
498-
None
499-
}
500-
})
501-
.collect::<HashSet<_>>();
480+
const TREE_URL: &str = "https://api.github.com\
481+
/repos/{repo_owner}/{repo_name}/git/trees/main?recursive=1";
482+
let tree_res = fetch(TREE_URL).await;
502483

503-
if !paths.contains(&"lib.ua".to_owned()) {
504-
cache_url(&url, Err(format!("lib.ua not found").into()));
484+
match tree_res {
485+
Err(_) => {
486+
cache_url(&url, tree_res);
505487
unmark_working(&original_url);
506488
return;
507489
}
490+
Ok(_) => {
491+
let tree = tree_res.unwrap();
492+
let tree: serde_json::Value = serde_json::from_str(&tree).unwrap();
493+
let tree = tree.get("tree").unwrap().as_array().unwrap();
494+
let paths = tree
495+
.iter()
496+
.filter_map(|entry| {
497+
let path = entry.get("path")?.as_str()?;
498+
if path.ends_with(".ua") {
499+
Some(path.to_string())
500+
} else {
501+
None
502+
}
503+
})
504+
.collect::<HashSet<_>>();
505+
506+
if !paths.contains("lib.ua") {
507+
cache_url(&url, Err("lib.ua not found".into()));
508+
unmark_working(&original_url);
509+
return;
510+
}
508511

509-
let results = join_all(
510-
paths.iter()
511-
.map(|path| {
512+
let results = join_all(paths.iter().map(|path| {
512513
let repo_owner = repo_owner.clone();
513514
let repo_name = repo_name.clone();
514515
async move {
515-
let fetch_url = format!("https://raw.githubusercontent.com/{repo_owner}/{repo_name}/main/{path}");
516+
let fetch_url = format!(
517+
"https://raw.githubusercontent.com\
518+
/{repo_owner}/{repo_name}/main/{path}",
519+
);
516520
let internal_path = Path::new("uiua-modules")
517521
.join(repo_owner)
518522
.join(repo_name)
519523
.join(path.clone());
520524

521525
(path, internal_path, fetch(fetch_url.as_str()).await)
522526
}
523-
})
524-
).await;
527+
}))
528+
.await;
525529

526-
for (original_path, internal_path, res) in results {
527-
if original_path.eq("lib.ua") {
528-
cache_url(&url, res.clone());
529-
}
530+
for (original_path, internal_path, res) in results {
531+
if original_path.eq("lib.ua") {
532+
cache_url(&url, res.clone());
533+
}
530534

531-
if let Ok(text) = res {
532-
let contents = text.as_bytes().to_vec();
533-
drop_file(internal_path.clone(), contents);
535+
if let Ok(text) = res {
536+
let contents = text.as_bytes().to_vec();
537+
drop_file(internal_path.clone(), contents);
538+
}
534539
}
535540
}
536541
}
@@ -540,7 +545,7 @@ impl SysBackend for WebBackend {
540545
None
541546
} else {
542547
logging::log!("Fetching url: {url}");
543-
mark_working(&original_url);
548+
mark_working(original_url);
544549
let original_url = original_url.to_string();
545550
spawn_local(async move {
546551
let res = fetch(&url).await;

0 commit comments

Comments
 (0)