feat: add centralized API service layer for frontend
All checks were successful
Build MIPS Binary / build (push) Successful in 5m18s

- Create frontend/src/api/mod.rs with centralized HTTP client and error handling
- Implement api::auth module (login, logout, check_auth, get_user)
- Implement api::torrent module (add, action, delete, start, stop, set_label, set_priority)
- Implement api::setup module (get_status, setup)
- Implement api::settings module (set_global_limits)
- Implement api::push module (get_public_key, subscribe)
- Update all components to use api service layer instead of direct gloo_net calls
- Add thiserror dependency for error handling
This commit is contained in:
spinline
2026-02-08 23:04:24 +03:00
parent 129a4c7586
commit cffc88443a
12 changed files with 387 additions and 281 deletions

View File

@@ -1,5 +1,6 @@
use leptos::wasm_bindgen::JsCast;
use leptos::*;
use crate::api;
#[component]
pub fn Sidebar() -> impl IntoView {
@@ -76,12 +77,8 @@ pub fn Sidebar() -> impl IntoView {
let handle_logout = move |_| {
spawn_local(async move {
let client = gloo_net::http::Request::post("/api/auth/logout");
if let Ok(resp) = client.send().await {
if resp.ok() {
// Force full reload to clear state
let _ = window().location().set_href("/login");
}
if api::auth::logout().await.is_ok() {
let _ = window().location().set_href("/login");
}
});
};