Fun changes
Some checks failed
CI / Python (lint + test) (push) Failing after 3m38s
CI / Rust (lint + test) (push) Failing after 3m32s
CI / Frontend (lint + typecheck) (push) Failing after 4m12s
Build and publish Docker image / build-and-push (push) Failing after 4m48s

This commit is contained in:
Andras Schmelczer 2026-04-04 22:59:44 +01:00
parent cd778dd088
commit 349a6c1d53
60 changed files with 1260 additions and 2600 deletions

View file

@ -731,6 +731,35 @@ pub async fn ensure_collections(
ensure_autodate_fields(client, base_url, &token, "short_urls").await?;
}
if !existing.iter().any(|n| n == "location_logs") {
let users_id = find_users_collection_id(client, base_url, &token).await?;
create_collection(
client,
base_url,
&token,
CreateCollection {
name: "location_logs".to_string(),
r#type: "base".to_string(),
fields: vec![
Field::relation("user", &users_id),
Field::number("latitude"),
Field::number("longitude"),
Field::text("postcode", true),
Field::autodate("created", true, false),
Field::autodate("updated", true, true),
],
list_rule: None,
view_rule: None,
create_rule: None,
update_rule: None,
delete_rule: None,
},
)
.await?;
} else {
ensure_autodate_fields(client, base_url, &token, "location_logs").await?;
}
if !existing.iter().any(|n| n == "ai_query_logs") {
let users_id = find_users_collection_id(client, base_url, &token).await?;
create_collection(
@ -743,7 +772,6 @@ pub async fn ensure_collections(
fields: vec![
Field::relation("user", &users_id),
Field::text("query", true),
Field::text("listing_type", false),
Field::text("response_filters", false),
Field::text("response_notes", false),
Field::number("tokens_used"),
@ -916,6 +944,48 @@ async fn poll_pocketbase_counts(state: &AppState) {
}
}
/// Insert a record into the `location_logs` collection.
/// Best-effort — logs warnings on failure but does not propagate errors.
pub async fn log_user_location(
state: &AppState,
user_id: &str,
latitude: f64,
longitude: f64,
postcode: &str,
) {
let token = match get_superuser_token(state).await {
Ok(tk) => tk,
Err(err) => {
warn!("Failed to auth superuser for location log: {err}");
return;
}
};
let pb_url = state.pocketbase_url.trim_end_matches('/');
let url = format!("{pb_url}/api/collections/location_logs/records");
let res = state
.http_client
.post(&url)
.header("Authorization", format!("Bearer {token}"))
.json(&serde_json::json!({
"user": user_id,
"latitude": latitude,
"longitude": longitude,
"postcode": postcode,
}))
.send()
.await;
match res {
Ok(resp) if resp.status().is_success() => {}
Ok(resp) => {
let status = resp.status();
warn!("Failed to log user location ({status})");
}
Err(err) => warn!("Failed to log user location: {err}"),
}
}
/// Insert a record into the `ai_query_logs` collection.
/// Best-effort — logs warnings on failure but does not propagate errors.
#[allow(clippy::too_many_arguments)]
@ -923,7 +993,6 @@ pub async fn log_ai_query(
state: &AppState,
user_id: &str,
query: &str,
listing_type: &str,
response_filters: &str,
response_notes: &str,
tokens_used: u64,
@ -946,7 +1015,6 @@ pub async fn log_ai_query(
.json(&serde_json::json!({
"user": user_id,
"query": query,
"listing_type": listing_type,
"response_filters": response_filters,
"response_notes": response_notes,
"tokens_used": tokens_used,