Files
vibetorrent/shared/src/server_fns/push.rs
spinline 4b3e713657
All checks were successful
Build MIPS Binary / build (push) Successful in 5m17s
refactor: move DB to shared crate, convert push endpoints to server functions, remove dead REST handlers
2026-02-10 02:05:04 +03:00

23 lines
686 B
Rust

use leptos::prelude::*;
#[server(GetPushPublicKey, "/api/server_fns")]
pub async fn get_public_key() -> Result<String, ServerFnError> {
let key = std::env::var("VAPID_PUBLIC_KEY")
.map_err(|_| ServerFnError::new("VAPID_PUBLIC_KEY not configured"))?;
Ok(key)
}
#[server(SubscribePush, "/api/server_fns")]
pub async fn subscribe_push(
endpoint: String,
p256dh: String,
auth: String,
) -> Result<(), ServerFnError> {
let db_ctx = expect_context::<crate::DbContext>();
db_ctx
.db
.save_push_subscription(&endpoint, &p256dh, &auth)
.await
.map_err(|e| ServerFnError::new(format!("Failed to save subscription: {}", e)))
}