From f5a874b4d29be268e3f73cd5fbab618957515cb7 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 27 Oct 2023 11:26:10 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20cargo-fmt=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/internet_identity/src/assets.rs | 101 ++++++++++++++-------------- 1 file changed, 49 insertions(+), 52 deletions(-) diff --git a/src/internet_identity/src/assets.rs b/src/internet_identity/src/assets.rs index b4769a3655..888deb21e9 100644 --- a/src/internet_identity/src/assets.rs +++ b/src/internet_identity/src/assets.rs @@ -164,7 +164,9 @@ pub fn init_assets() { body_hash, ); - certified_assets.assets.insert(path, (headers, Box::new(content))); + certified_assets + .assets + .insert(path, (headers, Box::new(content))); } }); } @@ -274,12 +276,7 @@ fn collect_assets_from_dir(dir: &Dir) -> Vec<(String, Vec, ContentEncoding, // TODO: add canister/lightweight test to ensure assets are loaded up // & certified successfully for asspath in asspaths { - assets.push(( - asspath, - content.clone(), - encoding, - content_type, - )); + assets.push((asspath, content.clone(), encoding, content_type)); } } assets @@ -313,51 +310,51 @@ fn filepath_to_urlpaths(file_path: String) -> Vec { // TODO: explain always return starting with / // Create paths, WITHOUT leading slash (leading lash is prepended later) - fn inner (elements: Vec<&str>, last: &str) -> Vec { - if elements.is_empty() && last == "index.html" { - // The special case of the root index.html, which we serve - // on both "/" and "/index.html" - vec!["".to_string(), "index.html".to_string()] - } else if last == "index.html" { - // An index.html in a subpath - let page = elements.join("/").to_string(); - vec![ - format!("{page}"), - format!("{page}/"), - format!("{page}/index.html"), - ] - } else if let Some(page) = last.strip_suffix(".html") { - // A (non-index) HTML page - let mut elements = elements.to_vec(); - elements.push(page); - let page = elements.join("/").to_string(); - vec![ - format!("{page}"), - format!("{page}/"), - format!("{page}/index.html"), - ] - } else if let Some(file) = last.strip_suffix(".gz") { - // A gzipped asset; remove suffix and retry - // XXX: this recursion is safe (i.e. not infinite) because - // we always reduce the argument (remove ".gz") - inner(elements, file) - } else { - // The default cases for any asset - let mut elements = elements.to_vec().clone(); - elements.push(last); - let prefix = elements.join("/").to_string(); - vec![prefix] - } - } - - let paths = match file_path.split('/').collect::>().split_last() { - None => { - // The argument was an empty string - // We can't really do much about this, so we fail explicitly - panic!("Expected non-empty filepath for asset"); - } - Some((last, elements)) => inner(elements.to_vec(), last) - }; + fn inner(elements: Vec<&str>, last: &str) -> Vec { + if elements.is_empty() && last == "index.html" { + // The special case of the root index.html, which we serve + // on both "/" and "/index.html" + vec!["".to_string(), "index.html".to_string()] + } else if last == "index.html" { + // An index.html in a subpath + let page = elements.join("/").to_string(); + vec![ + format!("{page}"), + format!("{page}/"), + format!("{page}/index.html"), + ] + } else if let Some(page) = last.strip_suffix(".html") { + // A (non-index) HTML page + let mut elements = elements.to_vec(); + elements.push(page); + let page = elements.join("/").to_string(); + vec![ + format!("{page}"), + format!("{page}/"), + format!("{page}/index.html"), + ] + } else if let Some(file) = last.strip_suffix(".gz") { + // A gzipped asset; remove suffix and retry + // XXX: this recursion is safe (i.e. not infinite) because + // we always reduce the argument (remove ".gz") + inner(elements, file) + } else { + // The default cases for any asset + let mut elements = elements.to_vec().clone(); + elements.push(last); + let prefix = elements.join("/").to_string(); + vec![prefix] + } + } + + let paths = match file_path.split('/').collect::>().split_last() { + None => { + // The argument was an empty string + // We can't really do much about this, so we fail explicitly + panic!("Expected non-empty filepath for asset"); + } + Some((last, elements)) => inner(elements.to_vec(), last), + }; // Prefix everything with "/" paths.into_iter().map(|path| format!("/{path}")).collect()