Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
segler-alex committed Dec 8, 2019
2 parents 9d9ffe0 + 7cb177a commit 892657e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/api/data/status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[derive(Serialize, Deserialize)]
pub struct Status {
pub supported_version: u32,
pub software_version: String,
pub software_version: Option<String>,
status: String,
stations: u64,
stations_broken: u64,
Expand All @@ -15,7 +15,7 @@ pub struct Status {
impl Status{
pub fn new(
supported_version: u32,
software_version: String,
software_version: Option<String>,
status: String,
stations: u64,
stations_broken: u64,
Expand Down Expand Up @@ -46,7 +46,9 @@ impl Status{
xml.begin_elem("stats")?;
let s = self.status.clone();
xml.attr_esc("supported_version", &self.supported_version.to_string())?;
xml.attr_esc("software_version", &self.software_version)?;
if let Some(software_version) = &self.software_version {
xml.attr_esc("software_version", &software_version)?;
}
xml.attr_esc("status", &s)?;
xml.attr_esc("stations", &self.stations.to_string())?;
xml.attr_esc("stations_broken", &self.stations_broken.to_string())?;
Expand Down
3 changes: 2 additions & 1 deletion src/api/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl Connection {
}
}
if countrycode.is_some() {
query.push_str(" AND CountryCode=:countrycode");
query.push_str(" AND UPPER(CountryCode)=UPPER(:countrycode)");
}
if state.is_some() {
if state_exact {
Expand All @@ -622,6 +622,7 @@ impl Connection {
let mut params = params!{
"name" => name.unwrap_or_default(),
"country" => country.unwrap_or_default(),
"countrycode" => countrycode.unwrap_or_default(),
"state" => state.unwrap_or_default(),
"language" => language.unwrap_or_default(),
"tag" => tag.unwrap_or_default(),
Expand Down
4 changes: 3 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn get_status(connection_new: &MysqlConnection) -> Result<Status, Box<dyn std::e
Ok(
Status::new(
1,
version.to_string(),
Some(version.to_string()),
"OK".to_string(),
connection_new.get_station_count_working()?,
connection_new.get_station_count_broken()?,
Expand Down Expand Up @@ -403,8 +403,10 @@ fn handle_connection_internal(connection: &db::Connection, connection_new: &Mysq
let mut handlebars = Handlebars::new();
let y = handlebars.register_template_file("docs.hbs", &format!("{}/{}",static_dir,"docs.hbs"));
if y.is_ok() {
let pkg_version = env!("CARGO_PKG_VERSION");
let mut data = Map::new();
data.insert(String::from("API_SERVER"), to_json(format!("http://{name}",name = header_host)));
data.insert(String::from("SERVER_VERSION"), to_json(format!("{version}",version = pkg_version)));
let rendered = handlebars.render("docs.hbs", &data);
match rendered {
Ok(rendered) => Ok(rouille::Response::html(rendered).with_no_cache()),
Expand Down
1 change: 1 addition & 0 deletions static/docs.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<div class="card-body">
<h1 class="card-title">Community Radio Station Index</h1>
<h2 class="card-subtitle mb-2 text-muted">General</h2>
<p>Server version: {{ SERVER_VERSION }}</p>
<p class="card-text ">This webservice can be used freely but without guarantee to work. I have been keeping it online since December, 2015, but downtimes are possible and I am not always home to fix it :) Please do not hesitate to send me ideas to improve the service at
<a href="mailto:[email protected]">segler_alex AT web DOT de</a>.
<br/>Please send a <span class="text-danger">descriptive User-Agent</span> in your HTTP requests, which makes it easier for me to get in touch with developers to help with the usage of the API. Something like <span class="text-info">"appname/appversion"</span>,
Expand Down

0 comments on commit 892657e

Please sign in to comment.