modernize: migrate to Leptos 0.8 and Server Functions architecture, break backend->shared loop
Some checks failed
Build MIPS Binary / build (push) Failing after 1m27s
Some checks failed
Build MIPS Binary / build (push) Failing after 1m27s
This commit is contained in:
26
shared/src/server_fns/mod.rs
Normal file
26
shared/src/server_fns/mod.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use leptos::*;
|
||||
use leptos::prelude::*;
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
use crate::xmlrpc::{self, RtorrentClient};
|
||||
|
||||
#[server(GetVersion, "/api/server_fns")]
|
||||
pub async fn get_version() -> Result<String, ServerFnError> {
|
||||
let socket_path = std::env::var("RTORRENT_SOCKET").unwrap_or_else(|_| "/tmp/rtorrent.sock".to_string());
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
{
|
||||
let client = RtorrentClient::new(&socket_path);
|
||||
match client.call("system.client_version", &[]).await {
|
||||
Ok(xml) => {
|
||||
let version = xmlrpc::parse_string_response(&xml).unwrap_or(xml);
|
||||
Ok(version)
|
||||
},
|
||||
Err(e) => Err(ServerFnError::ServerError(e.to_string())),
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "ssr"))]
|
||||
{
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user