2026-07-29 19:38:40 +02:00
|
|
|
#![cfg(feature = "ssr")]
|
|
|
|
|
|
|
|
|
|
pub mod oidc;
|
|
|
|
|
|
2026-08-05 07:20:40 +02:00
|
|
|
use arc_swap::ArcSwap;
|
2026-07-29 19:38:40 +02:00
|
|
|
use axum::extract::FromRef;
|
|
|
|
|
use leptos::prelude::LeptosOptions;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
use crate::content::Question;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct AppState {
|
|
|
|
|
pub leptos_options: LeptosOptions,
|
|
|
|
|
pub nats: async_nats::Client,
|
|
|
|
|
/// JetStream context - source of every NATS KV bucket this app
|
|
|
|
|
/// reads/writes (applicants, and whatever a `ResourceSpec` names).
|
|
|
|
|
pub jetstream: async_nats::jetstream::Context,
|
2026-08-05 07:20:40 +02:00
|
|
|
/// Swapped out wholesale on a `content::CONTENT_RELOAD_SUBJECT`
|
|
|
|
|
/// message (see `content::watch_for_reload`) - readers never hold
|
|
|
|
|
/// a lock, just an atomic pointer load, so a reload never blocks or
|
|
|
|
|
/// is blocked by an in-flight request.
|
|
|
|
|
pub questions: Arc<ArcSwap<HashMap<String, Question>>>,
|
2026-08-11 21:43:32 +02:00
|
|
|
/// Every bucket's event-sourced state graph, loaded from
|
|
|
|
|
/// `aggregates.yaml` (see `content::load_aggregates_from_gitea`) and
|
|
|
|
|
/// hot-swapped alongside `questions` on the same reload. A bucket
|
|
|
|
|
/// with no entry here isn't event-sourced - plain KV mutate-in-place
|
|
|
|
|
/// still works (see `answers.rs`).
|
|
|
|
|
pub aggregates: Arc<ArcSwap<HashMap<String, crate::aggregates::AggregateSchema>>>,
|
2026-08-23 13:03:29 +02:00
|
|
|
/// Site branding from the content repo's optional `site.yaml`
|
|
|
|
|
/// (title, wordmark, hero kind) - hot-swapped with `questions`/
|
|
|
|
|
/// `aggregates` on the same reload. Default = the historical uhhm
|
|
|
|
|
/// look.
|
|
|
|
|
pub site: Arc<ArcSwap<crate::content::SiteConfig>>,
|
2026-08-05 13:45:56 +02:00
|
|
|
/// `scheme://host` of the Gitea instance content is loaded from
|
|
|
|
|
/// (see `content::gitea_api_base`) - kept alongside `questions`
|
|
|
|
|
/// rather than re-derived per call, since `resolve_gitea_repo` needs
|
|
|
|
|
/// it too and has no other reason to see `CONTENT_REPO` itself.
|
|
|
|
|
pub gitea_base: String,
|
2026-07-29 19:38:40 +02:00
|
|
|
pub oidc: Arc<oidc::Oidc>,
|
|
|
|
|
/// `None` when `GARAGE_*` env vars aren't set - uploads are the one
|
|
|
|
|
/// optional feature, everything else works without Garage.
|
|
|
|
|
pub garage: Option<crate::upload::Garage>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromRef<AppState> for LeptosOptions {
|
|
|
|
|
fn from_ref(state: &AppState) -> Self {
|
|
|
|
|
state.leptos_options.clone()
|
|
|
|
|
}
|
|
|
|
|
}
|