Merge pull request #10 from diamante0018/main

feat: use current time as cache busting method
This commit is contained in:
mxve 2023-07-13 10:39:16 +02:00 committed by GitHub
commit 389643078d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
mod http;
use std::{fs, path::PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
#[derive(serde::Deserialize, serde::Serialize)]
struct CdnFile {
@ -17,6 +18,13 @@ struct Game<'a> {
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 {
let mut sha1 = sha1_smol::Sha1::new();
sha1.update(&fs::read(path).unwrap());
@ -28,7 +36,7 @@ fn update(game: &Game) {
format!(
"{}/files.json?{}",
MASTER,
rand::Rng::gen_range(&mut rand::thread_rng(), 0..1000)
get_cache_buster()
)
.as_str(),
))
@ -58,7 +66,7 @@ fn update(game: &Game) {
"{}/{}?{}",
MASTER,
file.name,
rand::Rng::gen_range(&mut rand::thread_rng(), 0..1000)
get_cache_buster()
),
&file_path,
);
@ -75,7 +83,7 @@ fn update(game: &Game) {
"{}/{}?{}",
MASTER,
file.name,
rand::Rng::gen_range(&mut rand::thread_rng(), 0..1000)
get_cache_buster()
),
&file_path,
);