Skip to content

Commit

Permalink
Inject Cargo Version into html Podcastindex-org#18
Browse files Browse the repository at this point in the history
  • Loading branch information
valcanobacon committed Jan 23, 2022
1 parent 7d2edea commit 4ee8c2f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "helipad"
version = "0.1.5"
version = "0.1.6"
edition = "2018"
build = "build.rs"

Expand All @@ -27,6 +27,7 @@ dbif = { path = 'dbif'}
lnd-rs = { path = "lnd-rs" }
voca_rs = "1.14.0"
configure_me = "0.4.0"
handlebars = "4.2.1"

[build-dependencies]
configure_me_codegen = "0.4.0"
6 changes: 3 additions & 3 deletions helipad.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
##: anything given here.

##: Overridden by env:HELIPAD_DATABASE_DIR
database_dir="/data/database.db"
database_dir="database.db"

##: Overridden by env:HELIPAD_LISTEN_PORT
listen_port=2112

##: Overridden by env:LND_ADMINMACAROON
macaroon="/lnd/data/chain/bitcoin/mainnet/admin.macaroon"
macaroon="admin.macaroon"

##: Overridden by env:LND_TLSCERT
cert="/lnd/tls.cert"
cert="tls.cert"

##: Overridden by env:LND_URL
lnd_url="https://127.0.0.1:10009"
9 changes: 6 additions & 3 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use std::error::Error;
use std::fmt;
use std::fs;
use voca_rs::*;
use handlebars::Handlebars;
use serde_json::json;



//Constants --------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -33,12 +36,12 @@ pub async fn home(ctx: Context) -> Response {
url::form_urlencoded::parse(v.as_bytes()).into_owned().collect()
}).unwrap_or_else(HashMap::new);

//println!("** Params: {:#?}", _params);

let reg = Handlebars::new();
let doc = fs::read_to_string("webroot/html/home.html").expect("Something went wrong reading the file.");
let doc_rendered = reg.render_template(&doc, &json!({"version": ctx.state.version})).expect("Something went wrong rendering the file");
return hyper::Response::builder()
.status(StatusCode::OK)
.body(format!("{}", doc).into())
.body(format!("{}", doc_rendered).into())
.unwrap();
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const LND_STANDARD_TLSCERT_LOCATION: &str = "/lnd/tls.cert";
pub struct AppState {
pub state_thing: String,
pub remote_ip: String,
pub version: String,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -257,6 +258,7 @@ async fn main() {
let app_state = AppState {
state_thing: some_state.clone(),
remote_ip: conn.remote_addr().to_string().clone(),
version: version.to_string(),
};

let database_file_path = db_filepath.clone();
Expand Down
4 changes: 2 additions & 2 deletions webroot/html/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy"
content="script-src cdnjs.cloudflare.com maxcdn.bootstrapcdn.com 'self';">
<title>Helipad (v0.1.5)</title>
<title>Helipad (v{{version}})</title>

<!-- Scripts -->
<script src="/script?name=jquery"></script>
Expand All @@ -30,7 +30,7 @@ <h5 class="titleHeader">Helipad: Boost Tracker</h5>
<div class="msg_history"></div>
</div>
</div>
<div class="versionFooter"><a href="https://github.com/Podcastindex-org/helipad">v0.1.5</a></div>
<div class="versionFooter"><a href="https://github.com/Podcastindex-org/helipad">v{{version}}</a></div>
</div>
</div>
</body>
Expand Down

0 comments on commit 4ee8c2f

Please sign in to comment.