Asset timestamping
This commit is contained in:
+3
-1
@@ -2,4 +2,6 @@ SALT=64_byte_string
|
||||
DATABASE_URL=postgres://xxx:xxx@localhost/xxx
|
||||
|
||||
METALS_API_KEY=xxx
|
||||
NUMISTA_API_KEY=xxx
|
||||
NUMISTA_API_KEY=xxx
|
||||
|
||||
ASSET_DIR=/opt/melt/public
|
||||
|
||||
@@ -82,6 +82,33 @@ impl ClientCtx {
|
||||
format!("{:.2}", AU_TO_USD.load(Ordering::Relaxed) as f32 / 1000.0)
|
||||
}
|
||||
|
||||
pub fn get_asset_timestamp(&self) -> u64 {
|
||||
let asset = "assets/style.css";
|
||||
match std::fs::metadata(format!(
|
||||
"{}/{}",
|
||||
std::env::var("ASSET_DIR").unwrap_or_else(|_| ".".to_string()),
|
||||
asset
|
||||
)) {
|
||||
Ok(metadata) => match metadata.modified() {
|
||||
Ok(time) => match time.duration_since(std::time::UNIX_EPOCH) {
|
||||
Ok(distance) => distance.as_secs(),
|
||||
Err(_) => {
|
||||
log::warn!("Unable to do math on webpack chat.js modified at timestamp");
|
||||
0
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
log::warn!("Unable to read metadata on webpack chat.js");
|
||||
0
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
log::warn!("Unable to open webpack chat.js for timestamp");
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns Duration representing request time.
|
||||
pub fn request_time(&self) -> Duration {
|
||||
Instant::now() - self.0.request_start
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
</script>
|
||||
|
||||
{% block stylesheets %}
|
||||
<link rel="stylesheet" type="text/css" href="/assets/style.css" nonce="{{ client.get_nonce() }}" />
|
||||
<link rel="stylesheet" type="text/css" href="/assets/style.css?{{ client.get_asset_timestamp()}}"
|
||||
nonce="{{ client.get_nonce() }}" />
|
||||
{#
|
||||
<link rel="stylesheet" type="text/css" href="/assets/print.css" media="print" nonce="{{ client.get_nonce() }}" /> #}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user