Files
hello-agent/vendor/rustdesk/src/hbbs_http.rs
T
mike 6807fe2bc0
build-windows / build-hello-agent-x64 (push) Successful in 4m52s
build-windows / sign-hello-agent-x64 (push) Successful in 5s
build-windows / validate-hello-agent-x64 (push) Successful in 6s
Implement signed API communication to improve security
2026-05-22 13:13:05 +02:00

42 lines
1.1 KiB
Rust

use hbb_common::ResultType;
use serde::de::DeserializeOwned;
use serde_json::{Map, Value};
#[cfg(feature = "flutter")]
pub mod account;
pub mod downloader;
mod http_client;
pub mod record_upload;
pub mod sign;
pub mod sync;
pub use http_client::{
create_http_client_async, create_http_client_async_with_url, create_http_client_with_url,
get_url_for_tls,
};
#[derive(Debug)]
pub enum HbbHttpResponse<T> {
ErrorFormat,
Error(String),
DataTypeFormat,
Data(T),
}
impl<T: DeserializeOwned> HbbHttpResponse<T> {
pub fn parse(body: &str) -> ResultType<Self> {
let map = serde_json::from_str::<Map<String, Value>>(body)?;
if let Some(error) = map.get("error") {
if let Some(err) = error.as_str() {
Ok(Self::Error(err.to_owned()))
} else {
Ok(Self::ErrorFormat)
}
} else {
match serde_json::from_value(Value::Object(map)) {
Ok(v) => Ok(Self::Data(v)),
Err(_) => Ok(Self::DataTypeFormat),
}
}
}
}