//! Client for the wiki backend API: the endpoints that SURVIVE the atproto
//! rewrite (the axum backend already serves these exact paths and evolves into the
//! AppView). Split out of `nhost.rs` so the cutover deletion boundary is exact:
//! `nhost.rs` (NHost auth + storage glue) is deleted wholesale, this module is kept
//! and repointed. Also home of the Bluesky public-AppView typeahead and the
//! atproto link types, which likewise outlive NHost.
use serde::Deserialize;
/// The wiki backend (a Rust axum service on Scaleway Serverless Containers,
/// fr-par). Hosts the atproto OAuth flow for linking a Bluesky account:
/// `GET /atproto/start?handle=&token=` begins linking and redirects back with
/// `?linked=success|error`.
///
/// Overridable at compile time with `WIKI_BACKEND_URL` (same pattern as
/// `logging.rs`), so a dev/staging build can point at a local backend or a future
/// AppView without editing code; unset, the constant is bit-identical to before.
pub const BACKEND_URL: &str = match option_env!("WIKI_BACKEND_URL") {
Some(url) => url,
None => "https://wikidioxusd0caa45e-wiki-backend.functions.fnc.fr-par.scw.cloud",
};
/// The URL that starts the atproto (Bluesky) account-linking flow for `handle`,
/// authenticated by the session JWT (both are URL-safe: a domain and base64url).
/// The backend redirects back with `?linked=success|error`.
pub fn atproto_start_url(handle: &str, token: &str) -> String {
format!("{BACKEND_URL}/atproto/start?handle={handle}&token={token}")
}
/// The URL of a stored file's bytes, with no credentials in it.
///
/// The storage service authenticates by `Authorization` header only — a `?token=`
/// in the query is decorative, and the URL resolves as an ANONYMOUS request. That
/// went unnoticed while every file was world-readable; once files are readable
/// only through the node that references them, such a request is refused.
///
/// So this is for FETCHES, which can set the header (see
/// [`crate::components::loader::use_file_object_url`]). An `
` or `