Compare commits
2 Commits
release-20
...
release-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
315a2f9a53 | ||
|
|
9d160a7ef5 |
@@ -52,18 +52,22 @@ async fn auth_middleware(
|
|||||||
request: Request<Body>,
|
request: Request<Body>,
|
||||||
next: Next,
|
next: Next,
|
||||||
) -> Result<Response, StatusCode> {
|
) -> Result<Response, StatusCode> {
|
||||||
// Skip auth for public paths
|
// Skip auth for public server functions
|
||||||
let path = request.uri().path();
|
let path = request.uri().path();
|
||||||
if path.starts_with("/api/server_fns/Login") // Login server fn
|
if path.starts_with("/api/server_fns/Login")
|
||||||
|
|| path.starts_with("/api/server_fns/login")
|
||||||
|| path.starts_with("/api/server_fns/GetSetupStatus")
|
|| path.starts_with("/api/server_fns/GetSetupStatus")
|
||||||
|
|| path.starts_with("/api/server_fns/get_setup_status")
|
||||||
|| path.starts_with("/api/server_fns/Setup")
|
|| path.starts_with("/api/server_fns/Setup")
|
||||||
|
|| path.starts_with("/api/server_fns/setup")
|
||||||
|| path.starts_with("/swagger-ui")
|
|| path.starts_with("/swagger-ui")
|
||||||
|| path.starts_with("/api-docs")
|
|| path.starts_with("/api-docs")
|
||||||
|| !path.starts_with("/api/") // Allow static files (frontend)
|
|| !path.starts_with("/api/")
|
||||||
{
|
{
|
||||||
return Ok(next.run(request).await);
|
return Ok(next.run(request).await);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Check token
|
// Check token
|
||||||
if let Some(token) = jar.get("auth_token") {
|
if let Some(token) = jar.get("auth_token") {
|
||||||
use jsonwebtoken::{decode, Validation, DecodingKey};
|
use jsonwebtoken::{decode, Validation, DecodingKey};
|
||||||
@@ -221,6 +225,18 @@ async fn main() {
|
|||||||
tracing::info!("Socket: {}", args.socket);
|
tracing::info!("Socket: {}", args.socket);
|
||||||
tracing::info!("Port: {}", args.port);
|
tracing::info!("Port: {}", args.port);
|
||||||
|
|
||||||
|
// Force linking of server functions from shared crate for registration on Mac
|
||||||
|
{
|
||||||
|
use shared::server_fns::auth::*;
|
||||||
|
let _ = get_setup_status;
|
||||||
|
let _ = setup;
|
||||||
|
let _ = login;
|
||||||
|
let _ = logout;
|
||||||
|
let _ = get_user;
|
||||||
|
tracing::info!("Server functions linked successfully.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ... rest of the main function ...
|
// ... rest of the main function ...
|
||||||
// Startup Health Check
|
// Startup Health Check
|
||||||
let socket_path = std::path::Path::new(&args.socket);
|
let socket_path = std::path::Path::new(&args.socket);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ edition = "2021"
|
|||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
leptos = { version = "0.8.15", features = ["csr", "msgpack"] }
|
leptos = { version = "0.8.15", features = ["csr", "msgpack", "nightly"] }
|
||||||
leptos_router = { version = "0.8.11" }
|
leptos_router = { version = "0.8.11" }
|
||||||
|
|
||||||
console_error_panic_hook = "0.1"
|
console_error_panic_hook = "0.1"
|
||||||
|
|||||||
@@ -138,8 +138,18 @@ pub fn SonnerList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Thread local storage for global access without Context
|
||||||
|
thread_local! {
|
||||||
|
static TOASTS: std::cell::RefCell<Option<RwSignal<Vec<ToastData>>>> = std::cell::RefCell::new(None);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn provide_toaster() {
|
pub fn provide_toaster() {
|
||||||
let toasts = RwSignal::new(Vec::<ToastData>::new());
|
let toasts = RwSignal::new(Vec::<ToastData>::new());
|
||||||
|
|
||||||
|
// Set global thread_local
|
||||||
|
TOASTS.with(|t| *t.borrow_mut() = Some(toasts));
|
||||||
|
|
||||||
|
// Also provide context for components
|
||||||
provide_context(ToasterStore { toasts });
|
provide_context(ToasterStore { toasts });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +201,9 @@ pub fn Toaster(#[prop(default = SonnerPosition::default())] position: SonnerPosi
|
|||||||
|
|
||||||
// Global Helper Functions
|
// Global Helper Functions
|
||||||
pub fn toast(title: impl Into<String>, variant: ToastType) {
|
pub fn toast(title: impl Into<String>, variant: ToastType) {
|
||||||
if let Some(store) = use_context::<ToasterStore>() {
|
let signal_opt = TOASTS.with(|t| *t.borrow());
|
||||||
|
|
||||||
|
if let Some(toasts) = signal_opt {
|
||||||
let id = js_sys::Math::random().to_bits();
|
let id = js_sys::Math::random().to_bits();
|
||||||
let new_toast = ToastData {
|
let new_toast = ToastData {
|
||||||
id,
|
id,
|
||||||
@@ -201,18 +213,16 @@ pub fn toast(title: impl Into<String>, variant: ToastType) {
|
|||||||
duration: 4000,
|
duration: 4000,
|
||||||
};
|
};
|
||||||
|
|
||||||
store.toasts.update(|t| t.push(new_toast.clone()));
|
toasts.update(|t| t.push(new_toast.clone()));
|
||||||
|
|
||||||
// Auto remove after duration
|
// Auto remove after duration
|
||||||
let duration = new_toast.duration;
|
let duration = new_toast.duration;
|
||||||
leptos::task::spawn_local(async move {
|
leptos::task::spawn_local(async move {
|
||||||
gloo_timers::future::TimeoutFuture::new(duration as u32).await;
|
gloo_timers::future::TimeoutFuture::new(duration as u32).await;
|
||||||
if let Some(store) = use_context::<ToasterStore>() {
|
toasts.update(|vec| vec.retain(|t| t.id != id));
|
||||||
store.toasts.update(|vec| vec.retain(|t| t.id != id));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
gloo_console::warn!("ToasterStore not found. Make sure <Toaster /> is mounted.");
|
gloo_console::warn!("ToasterStore not found (global static). Make sure provide_toaster() is called.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub struct SetupStatus {
|
|||||||
pub completed: bool,
|
pub completed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server(GetSetupStatus, "/api/server_fns/GetSetupStatus", input = MsgPack, output = MsgPack)]
|
#[server(GetSetupStatus, "/api/server_fns", input = MsgPack, output = MsgPack)]
|
||||||
pub async fn get_setup_status() -> Result<SetupStatus, ServerFnError> {
|
pub async fn get_setup_status() -> Result<SetupStatus, ServerFnError> {
|
||||||
use crate::DbContext;
|
use crate::DbContext;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ pub async fn get_setup_status() -> Result<SetupStatus, ServerFnError> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server(Setup, "/api/server_fns/Setup", input = MsgPack, output = MsgPack)]
|
#[server(Setup, "/api/server_fns", input = MsgPack, output = MsgPack)]
|
||||||
pub async fn setup(username: String, password: String) -> Result<(), ServerFnError> {
|
pub async fn setup(username: String, password: String) -> Result<(), ServerFnError> {
|
||||||
use crate::DbContext;
|
use crate::DbContext;
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ pub async fn setup(username: String, password: String) -> Result<(), ServerFnErr
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server(Login, "/api/server_fns/Login", input = MsgPack, output = MsgPack)]
|
#[server(Login, "/api/server_fns", input = MsgPack, output = MsgPack)]
|
||||||
pub async fn login(username: String, password: String) -> Result<UserResponse, ServerFnError> {
|
pub async fn login(username: String, password: String) -> Result<UserResponse, ServerFnError> {
|
||||||
use crate::DbContext;
|
use crate::DbContext;
|
||||||
use leptos_axum::ResponseOptions;
|
use leptos_axum::ResponseOptions;
|
||||||
@@ -111,7 +111,7 @@ pub async fn login(username: String, password: String) -> Result<UserResponse, S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server(Logout, "/api/server_fns/Logout", input = MsgPack, output = MsgPack)]
|
#[server(Logout, "/api/server_fns", input = MsgPack, output = MsgPack)]
|
||||||
pub async fn logout() -> Result<(), ServerFnError> {
|
pub async fn logout() -> Result<(), ServerFnError> {
|
||||||
use leptos_axum::ResponseOptions;
|
use leptos_axum::ResponseOptions;
|
||||||
use cookie::{Cookie, SameSite};
|
use cookie::{Cookie, SameSite};
|
||||||
@@ -132,7 +132,7 @@ pub async fn logout() -> Result<(), ServerFnError> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[server(GetUser, "/api/server_fns/GetUser", input = MsgPack, output = MsgPack)]
|
#[server(GetUser, "/api/server_fns", input = MsgPack, output = MsgPack)]
|
||||||
pub async fn get_user() -> Result<Option<UserResponse>, ServerFnError> {
|
pub async fn get_user() -> Result<Option<UserResponse>, ServerFnError> {
|
||||||
use axum::http::HeaderMap;
|
use axum::http::HeaderMap;
|
||||||
use leptos_axum::extract;
|
use leptos_axum::extract;
|
||||||
|
|||||||
BIN
vibetorrent.db-shm
Normal file
BIN
vibetorrent.db-shm
Normal file
Binary file not shown.
BIN
vibetorrent.db-wal
Normal file
BIN
vibetorrent.db-wal
Normal file
Binary file not shown.
Reference in New Issue
Block a user