Make overrides option

This commit is contained in:
Daniel 2023-05-18 08:11:47 -04:00
parent e042821848
commit 402fe18e18
2 changed files with 4 additions and 3 deletions

View file

@ -74,7 +74,7 @@ pub struct PasteConfig {
pub delete_expired_files: Option<CleanupConfig>,
/// Highlight override.
#[serde(default)]
pub highlight_override: HashMap<String, String>,
pub highlight_override: Option<HashMap<String, String>>,
}
/// Cleanup configuration.

View file

@ -95,8 +95,9 @@ async fn serve(
None => "default",
});
let mime_str = mime_type.to_string();
let overrides = &config.paste.highlight_override;
values.insert("type", if overrides.contains_key(&mime_str) { overrides[&mime_str].as_str() } else { "" });
if let Some(overrides) = &config.paste.highlight_override {
values.insert("type", if overrides.contains_key(&mime_str) { overrides[&mime_str].as_str() } else { "" });
}
let rendered = tmpl.fill_in(&values);
return Ok(HttpResponse::Ok().content_type(mime::TEXT_HTML).body(rendered.to_string()))
}