Fix: Bug with file names
This commit is contained in:
@@ -21,8 +21,16 @@ impl SearchResult {
|
|||||||
}
|
}
|
||||||
impl From<&File> for SearchResult {
|
impl From<&File> for SearchResult {
|
||||||
fn from(file: &File) -> Self {
|
fn from(file: &File) -> Self {
|
||||||
|
let name = file
|
||||||
|
.filename
|
||||||
|
.split('.')
|
||||||
|
.next()
|
||||||
|
.ok_or(file.filename.clone())
|
||||||
|
.unwrap()
|
||||||
|
.to_string();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
name: file.filename.clone(),
|
name,
|
||||||
modified: file.last_modified.clone(),
|
modified: file.last_modified.clone(),
|
||||||
size: file.filesize,
|
size: file.filesize,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ fn search_to_html(results: Vec<SearchResult>) -> String {
|
|||||||
);
|
);
|
||||||
HTML_TEMPLATE.replace("{body}", &body)
|
HTML_TEMPLATE.replace("{body}", &body)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn redirect(req: &Request) -> Response {
|
fn redirect(req: &Request) -> Response {
|
||||||
info!("Redirecting request: {:?}", req);
|
info!("Redirecting request: {:?}", req);
|
||||||
|
|
||||||
@@ -96,18 +97,13 @@ fn redirect(req: &Request) -> Response {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let Some(first) = response.get(0) else {
|
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 :()")
|
return Response::text("Could not find any awesome page to redirect you to :()")
|
||||||
.with_status_code(404);
|
.with_status_code(404);
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(name) = first.name.split('.').next() else {
|
info!("Redirecting to: /{}", first.name);
|
||||||
error!("Error getting name from response!");
|
Response::redirect_303(format!("/{}", first.name))
|
||||||
return Response::text("No fitting awesome list found :(").with_status_code(404);
|
|
||||||
};
|
|
||||||
|
|
||||||
info!("Redirecting to: /{}", name);
|
|
||||||
Response::redirect_303(format!("/{}", name))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query_elastic_search(query: String) -> Result<Vec<SearchResult>, Box<dyn Error>> {
|
fn query_elastic_search(query: String) -> Result<Vec<SearchResult>, Box<dyn Error>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user