Fix: Bug with file names

This commit is contained in:
Jonas Zeunert
2024-04-24 00:05:48 +02:00
parent 313faf1864
commit 3046ea6d97
2 changed files with 14 additions and 10 deletions

View File

@@ -21,8 +21,16 @@ impl SearchResult {
}
impl From<&File> for SearchResult {
fn from(file: &File) -> Self {
let name = file
.filename
.split('.')
.next()
.ok_or(file.filename.clone())
.unwrap()
.to_string();
Self {
name: file.filename.clone(),
name,
modified: file.last_modified.clone(),
size: file.filesize,
}

View File

@@ -75,6 +75,7 @@ fn search_to_html(results: Vec<SearchResult>) -> String {
);
HTML_TEMPLATE.replace("{body}", &body)
}
fn redirect(req: &Request) -> Response {
info!("Redirecting request: {:?}", req);
@@ -96,18 +97,13 @@ fn redirect(req: &Request) -> Response {
};
let Some(first) = response.get(0) else {
error!("No search results");
error!("No search results. Should not happen because we checked before!");
return Response::text("Could not find any awesome page to redirect you to :()")
.with_status_code(404);
};
let Some(name) = first.name.split('.').next() else {
error!("Error getting name from response!");
return Response::text("No fitting awesome list found :(").with_status_code(404);
};
info!("Redirecting to: /{}", name);
Response::redirect_303(format!("/{}", name))
info!("Redirecting to: /{}", first.name);
Response::redirect_303(format!("/{}", first.name))
}
fn query_elastic_search(query: String) -> Result<Vec<SearchResult>, Box<dyn Error>> {