From aceb51c21c17c032cd57068bde0b77beb81467f2 Mon Sep 17 00:00:00 2001 From: trisua Date: Sun, 22 Jun 2025 18:53:02 -0400 Subject: [PATCH] add: CACHE_BREAKER env var --- README.md | 2 +- crates/app/src/assets.rs | 9 ++++++++- crates/app/src/public/html/body.lisp | 1 + crates/app/src/public/html/macros.lisp | 2 +- crates/app/src/public/html/profile/settings.lisp | 2 +- crates/app/src/public/js/me.js | 5 +++-- crates/app/src/routes/api/v1/auth/profile.rs | 6 +++--- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dec9f1e..e1ac999 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Tetratto **requires** Cloudflare Turnstile for registrations. Testing keys are l A `docs` directory will be generated in the same directory that you ran the `tetratto` binary in. **Markdown** files placed here will be served at `/doc/{*file_name}`. For other types of assets, you can place them in the generated `public` directory. This directory serves everything at `/public/{*file_name}`. -You can configure your port through the `port` key of the configuration file. You can also run the server with the `PORT` environment variable, which will override whatever is set in the configuration file. +You can configure your port through the `port` key of the configuration file. You can also run the server with the `PORT` environment variable, which will override whatever is set in the configuration file. You can also use the `CACHE_BREAKER` environment variable to specify a version number to be used in static asset links in order to break cache entries. ## Usage (as a user) diff --git a/crates/app/src/assets.rs b/crates/app/src/assets.rs index 5533a77..130b4fc 100644 --- a/crates/app/src/assets.rs +++ b/crates/app/src/assets.rs @@ -495,6 +495,13 @@ pub(crate) async fn initial_context( } ctx.insert("lang", &lang.data); - ctx.insert("random_cache_breaker", &CACHE_BREAKER.clone()); + ctx.insert( + "random_cache_breaker", + &if let Ok(c) = std::env::var("CACHE_BREAKER") { + c + } else { + CACHE_BREAKER.clone() + }, + ); ctx } diff --git a/crates/app/src/public/html/body.lisp b/crates/app/src/public/html/body.lisp index 2551635..370a608 100644 --- a/crates/app/src/public/html/body.lisp +++ b/crates/app/src/public/html/body.lisp @@ -322,6 +322,7 @@ \"Spotify\", { token: new_token, + refresh_token: new_refresh_token, expires_in: expires_in.toString(), name: profile.display_name, }, diff --git a/crates/app/src/public/html/macros.lisp b/crates/app/src/public/html/macros.lisp index 7691ee9..b2e8863 100644 --- a/crates/app/src/public/html/macros.lisp +++ b/crates/app/src/public/html/macros.lisp @@ -136,7 +136,7 @@ ("class" "dropdown") ("style" "width: max-content") (button - ("class" "camo raised small") + ("class" "raised small") ("onclick" "trigger('atto::hooks::dropdown', [event])") ("exclude" "dropdown") (icon (text "sliders-horizontal")) diff --git a/crates/app/src/public/html/profile/settings.lisp b/crates/app/src/public/html/profile/settings.lisp index 6bba68e..489805c 100644 --- a/crates/app/src/public/html/profile/settings.lisp +++ b/crates/app/src/public/html/profile/settings.lisp @@ -20,7 +20,7 @@ ("class" "dropdown") ("style" "width: max-content") (button - ("class" "camo raised small") + ("class" "raised small") ("onclick" "trigger('atto::hooks::dropdown', [event])") ("exclude" "dropdown") (icon (text "sliders-horizontal")) diff --git a/crates/app/src/public/js/me.js b/crates/app/src/public/js/me.js index 96ac95f..fc99248 100644 --- a/crates/app/src/public/js/me.js +++ b/crates/app/src/public/js/me.js @@ -300,7 +300,7 @@ self.define( "repost", - ( + async ( _, id, content, @@ -308,6 +308,7 @@ do_not_redirect = false, is_stack = false, ) => { + await trigger("atto::debounce", ["posts::create"]); return new Promise((resolve, _) => { fetch(`/api/v1/posts/${id}/repost`, { method: "POST", @@ -892,7 +893,7 @@ return; } - const now = new Date().getTime(); + const now = Date.now(); const updated = Number.parseInt(updated_) + 8000; let elapsed_since_update = now - updated; diff --git a/crates/app/src/routes/api/v1/auth/profile.rs b/crates/app/src/routes/api/v1/auth/profile.rs index 834f317..de177fa 100644 --- a/crates/app/src/routes/api/v1/auth/profile.rs +++ b/crates/app/src/routes/api/v1/auth/profile.rs @@ -30,7 +30,7 @@ use tetratto_core::{ }; use tetratto_core::cache::redis::Commands; use tetratto_shared::{ - hash::{self, random_id}, + hash::{hash, salt, random_id}, unix_epoch_timestamp, }; @@ -185,7 +185,7 @@ pub async fn append_associations_request( // resolve tokens for token in req.tokens { - let hashed = hash::hash(token); + let hashed = hash(token); let user_from_token = match data.get_user_by_token(&hashed).await { Ok(ua) => ua, Err(_) => continue, @@ -556,7 +556,7 @@ pub async fn subscription_handler( pub async fn handle_socket(socket: WebSocket, db: DataManager, user_id: String, stream_id: String) { let (mut sink, mut stream) = socket.split(); - let socket_id = tetratto_shared::hash::salt(); + let socket_id = salt(); db.0.1 .incr("atto.active_connections:users".to_string()) .await;