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>, pub delete_expired_files: Option<CleanupConfig>,
/// Highlight override. /// Highlight override.
#[serde(default)] #[serde(default)]
pub highlight_override: HashMap<String, String>, pub highlight_override: Option<HashMap<String, String>>,
} }
/// Cleanup configuration. /// Cleanup configuration.

View file

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