Merge pull request #10 from diamante0018/main
feat: use current time as cache busting method
This commit is contained in:
commit
389643078d
14
src/main.rs
14
src/main.rs
@ -1,5 +1,6 @@
|
|||||||
mod http;
|
mod http;
|
||||||
use std::{fs, path::PathBuf};
|
use std::{fs, path::PathBuf};
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
struct CdnFile {
|
struct CdnFile {
|
||||||
@ -17,6 +18,13 @@ struct Game<'a> {
|
|||||||
|
|
||||||
const MASTER: &str = "https://master.alterware.dev";
|
const MASTER: &str = "https://master.alterware.dev";
|
||||||
|
|
||||||
|
fn get_cache_buster() -> u64 {
|
||||||
|
match SystemTime::now().duration_since(UNIX_EPOCH) {
|
||||||
|
Ok(n) => return n.as_secs(),
|
||||||
|
Err(_) => return 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn file_get_sha1(path: &PathBuf) -> String {
|
fn file_get_sha1(path: &PathBuf) -> String {
|
||||||
let mut sha1 = sha1_smol::Sha1::new();
|
let mut sha1 = sha1_smol::Sha1::new();
|
||||||
sha1.update(&fs::read(path).unwrap());
|
sha1.update(&fs::read(path).unwrap());
|
||||||
@ -28,7 +36,7 @@ fn update(game: &Game) {
|
|||||||
format!(
|
format!(
|
||||||
"{}/files.json?{}",
|
"{}/files.json?{}",
|
||||||
MASTER,
|
MASTER,
|
||||||
rand::Rng::gen_range(&mut rand::thread_rng(), 0..1000)
|
get_cache_buster()
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
))
|
))
|
||||||
@ -58,7 +66,7 @@ fn update(game: &Game) {
|
|||||||
"{}/{}?{}",
|
"{}/{}?{}",
|
||||||
MASTER,
|
MASTER,
|
||||||
file.name,
|
file.name,
|
||||||
rand::Rng::gen_range(&mut rand::thread_rng(), 0..1000)
|
get_cache_buster()
|
||||||
),
|
),
|
||||||
&file_path,
|
&file_path,
|
||||||
);
|
);
|
||||||
@ -75,7 +83,7 @@ fn update(game: &Game) {
|
|||||||
"{}/{}?{}",
|
"{}/{}?{}",
|
||||||
MASTER,
|
MASTER,
|
||||||
file.name,
|
file.name,
|
||||||
rand::Rng::gen_range(&mut rand::thread_rng(), 0..1000)
|
get_cache_buster()
|
||||||
),
|
),
|
||||||
&file_path,
|
&file_path,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user