Last night

This commit is contained in:
Andras Schmelczer 2026-02-08 10:21:37 +00:00
parent 2906b01734
commit 42ee2d4c51
47 changed files with 848 additions and 478 deletions

View file

@ -14,12 +14,13 @@ use std::sync::Arc;
use anyhow::{bail, Context};
use axum::middleware;
use axum::routing::{any, get};
use axum::routing::{any, get, post};
use axum::Router;
use clap::Parser;
use tower_http::compression::CompressionLayer;
use tower_http::cors::{Any, CorsLayer};
use tower_http::services::ServeDir;
use tower_http::services::{ServeDir, ServeFile};
use tower_http::trace::TraceLayer;
use tracing::{info, warn};
use tracing_subscriber::EnvFilter;
@ -49,9 +50,9 @@ struct Cli {
#[arg(long)]
dist: Option<PathBuf>,
/// URL of the OG screenshot sidecar (e.g. http://og-screenshot:8002)
#[arg(long, env = "OG_SIDECAR_URL")]
og_sidecar_url: Option<String>,
/// URL of the screenshot service (e.g. http://screenshot:8002)
#[arg(long, env = "SCREENSHOT_URL")]
screenshot_url: String,
/// Public-facing URL for absolute og:image URLs
#[arg(
@ -63,7 +64,15 @@ struct Cli {
/// PocketBase server URL for authentication (e.g. http://localhost:8090)
#[arg(long, env = "POCKETBASE_URL")]
pocketbase_url: Option<String>,
pocketbase_url: String,
/// Ollama server URL for AI area summaries (e.g. http://ollama:11434)
#[arg(long, env = "OLLAMA_URL")]
ollama_url: String,
/// Ollama model name for area summaries
#[arg(long, env = "OLLAMA_MODEL", default_value = "gemma3:12b")]
ollama_model: String,
}
#[tokio::main]
@ -168,6 +177,11 @@ async fn main() -> anyhow::Result<()> {
.iter()
.map(|name| format!("max_{}", name))
.collect();
let avg_keys: Vec<String> = property_data
.feature_names
.iter()
.map(|name| format!("avg_{}", name))
.collect();
let poi_category_groups = poi_data.category_groups()?;
@ -203,12 +217,7 @@ async fn main() -> anyhow::Result<()> {
let http_client = reqwest::Client::new();
if cli.og_sidecar_url.is_some() {
info!(
"OG sidecar configured: {}",
cli.og_sidecar_url.as_deref().unwrap()
);
}
info!("Screenshot service configured: {}", cli.screenshot_url);
let features_response = routes::build_features_response(&property_data);
info!(
@ -223,9 +232,8 @@ async fn main() -> anyhow::Result<()> {
postcode_data.postcodes.len(),
);
if let Some(ref pb_url) = cli.pocketbase_url {
info!("PocketBase configured: {}", pb_url);
}
info!("PocketBase configured: {}", cli.pocketbase_url);
info!("Ollama configured: {} (model: {})", cli.ollama_url, cli.ollama_model);
let token_cache = Arc::new(auth::TokenCache::new());
@ -239,13 +247,16 @@ async fn main() -> anyhow::Result<()> {
feature_name_to_index,
min_keys,
max_keys,
avg_keys,
poi_category_groups,
features_response,
og_sidecar_url: cli.og_sidecar_url,
screenshot_url: cli.screenshot_url,
public_url: cli.public_url,
index_html,
http_client,
pocketbase_url: cli.pocketbase_url,
ollama_url: cli.ollama_url,
ollama_model: cli.ollama_model,
token_cache,
});
@ -266,6 +277,7 @@ async fn main() -> anyhow::Result<()> {
let state_export = state.clone();
let state_crawler = state.clone();
let state_pb = state.clone();
let state_area_summary = state.clone();
let api = Router::new()
.route(
@ -310,7 +322,11 @@ async fn main() -> anyhow::Result<()> {
"/api/export",
get(move |query| routes::get_export(state_export.clone(), query)),
)
.route("/api/me", get(routes::get_me));
.route("/api/me", get(routes::get_me))
.route(
"/api/area-summary",
post(move |body| routes::post_area_summary(state_area_summary.clone(), body)),
);
// Add tile routes
let reader_tile = tile_reader.clone();
@ -336,7 +352,10 @@ async fn main() -> anyhow::Result<()> {
);
let app = if frontend_dist.exists() {
api.fallback_service(ServeDir::new(&frontend_dist))
api.fallback_service(
ServeDir::new(&frontend_dist)
.not_found_service(ServeFile::new(frontend_dist.join("index.html"))),
)
} else {
api
};