No browser storage for referrals; the birth chart opens at the drawn chart
CI / test (push) Successful in 1m41s
CI / build (push) Successful in 5m22s
CI / deploy (push) Skipped

The share page stores nothing in the browser any more: the shared link
that brought a visitor travels in its login link (/belepes?ref=...) to
the Google, Apple and password sign-up. The backend counts the same
visitor of a link once in half an hour, instead of a sessionStorage flag.

The public birth chart scrolls to the drawn chart after a calculation
and when coming back to the page. Tabs scrolled to themselves on every
re-render of their parent when the address had a tab (#bolygok); they
now react only to the tab ids and hash changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-21 21:13:41 +00:00
co-authored by Claude Opus 5.5
parent b41dc31f3e
commit 8b8285b5d2
12 changed files with 60 additions and 61 deletions
+4
View File
@@ -47,6 +47,9 @@ pub struct AppState {
pub calculator_limiter: LoginLimiter,
/// The public place search (typing makes several calls), per visitor address.
pub places_limiter: LoginLimiter,
/// Share visits already counted (link and visitor address, for half an hour):
/// a reload is not a new visit, without storing anything in the browser.
pub share_visits: LoginLimiter,
pub models: models::Catalog,
pub stripe: stripe::Client,
}
@@ -60,6 +63,7 @@ impl AppState {
login_limiter: LoginLimiter::new(10, Duration::from_secs(15 * 60)),
calculator_limiter: LoginLimiter::new(30, Duration::from_secs(60 * 60)),
places_limiter: LoginLimiter::new(300, Duration::from_secs(60 * 60)),
share_visits: LoginLimiter::new(1, Duration::from_secs(30 * 60)),
models: models::Catalog::new(&config.openrouter_models_url),
stripe: stripe::Client::default(),
db,
+5
View File
@@ -326,6 +326,11 @@ pub async fn visit(
if sharer || same_place || is_robot(user_agent(&headers).as_deref()) {
return Ok(Json(json!({ "counted": false })));
}
// The same visitor again within half an hour (a reload, back and forth).
let visitor = format!("{}:{}", share.slug, client_ip(&headers).unwrap_or_default());
if state.share_visits.hit(&visitor).is_err() {
return Ok(Json(json!({ "counted": false })));
}
let mut tx = state.db.begin().await?;
sqlx::query("UPDATE shares SET view_count = view_count + 1 WHERE id = $1").bind(share.id).execute(&mut *tx).await?;
let rewarded = sqlx::query(
+7 -4
View File
@@ -1046,10 +1046,13 @@ async fn a_visit_by_someone_else_earns_one_question_once(pool: PgPool) {
app.get(&visit.replace("/visit", ""), None).await;
// someone else: counted, and the reward comes once
for _ in 0..2 {
let r = app.call_with("POST", &visit, None, None, &[browser, elsewhere]).await;
assert_eq!(r.body["counted"], true);
}
let r = app.call_with("POST", &visit, None, None, &[browser, elsewhere]).await;
assert_eq!(r.body["counted"], true);
// the same visitor again soon (a reload) is not a new visit
let r = app.call_with("POST", &visit, None, None, &[browser, elsewhere]).await;
assert_eq!(r.body["counted"], false);
let r = app.call_with("POST", &visit, None, None, &[browser, ("x-real-ip", "198.51.100.3")]).await;
assert_eq!(r.body["counted"], true);
let body = me().await;
assert_eq!(
(body["analyses_left"]["question"].as_i64(), &body["share_reward_granted"]),