fix: link to pdf

This commit is contained in:
Ondrej Vlach 2023-12-09 17:14:31 +01:00
parent f5fec79296
commit 5af90d846c
Signed by: ovlach
GPG Key ID: 4FF1A23B4914DE70
2 changed files with 10 additions and 1 deletions

View File

@ -28,7 +28,7 @@ default_person: &State<DefaultPerson>, frontend_svc: &State<FrontendSVCConfig>,
cv, cv,
lang: LanguageDescription::new(language.language.as_str(), "ovlach_frontend"), lang: LanguageDescription::new(language.language.as_str(), "ovlach_frontend"),
contact_svc: frontend_svc.inner().contact_service.clone(), contact_svc: frontend_svc.inner().contact_service.clone(),
pdf_download_url: format!("{}/cv/{}/output.pdf", frontend_svc.inner().pdf_service.clone(), default_person.default_person_name) pdf_download_url: format!("{}/cv/{}/{}/output.pdf", frontend_svc.inner().pdf_service.clone(), default_person.default_person_name, language.language) // route: /cv/<username>/<language>/output.pdf
}, },
Err(e) => { Err(e) => {
error!("Can't fetch CV data from backend {:?}", e); error!("Can't fetch CV data from backend {:?}", e);

View File

@ -4,6 +4,13 @@ use phf::phf_map;
pub struct RequestLanguage { pub struct RequestLanguage {
pub language: String, pub language: String,
pub simple_language: String,
}
fn find_key_for_value<'a>(map: &'a phf::Map<&'a str, &'a str>, value: &str) -> Option<&'a str> {
map.into_iter()
.find_map(|(key, &val)| if val == value { Some(*key) } else { None })
} }
static LANG_TO_CODES: phf::Map<&'static str, &'static str> = phf_map! { static LANG_TO_CODES: phf::Map<&'static str, &'static str> = phf_map! {
@ -18,9 +25,11 @@ impl<'r> FromParam<'r> for RequestLanguage {
match LANG_TO_CODES.get(param) { match LANG_TO_CODES.get(param) {
Some(val) => Ok(RequestLanguage { Some(val) => Ok(RequestLanguage {
language: val.to_string(), language: val.to_string(),
simple_language: find_key_for_value(&LANG_TO_CODES, val).unwrap_or("un").to_string(),
}), }),
None => Ok(RequestLanguage { None => Ok(RequestLanguage {
language: LANG_TO_CODES["en"].to_string(), language: LANG_TO_CODES["en"].to_string(),
simple_language: "en".to_string(),
}), }),
} }
} }