fix: fixed release builds
This commit is contained in:
@@ -9,13 +9,6 @@ use serde::{Deserialize, Serialize};
|
||||
use crate::{payload_types::Parameters, adapter::BeaconAdapter, error::BeaconError};
|
||||
use crate::version::Version;
|
||||
|
||||
mod exec;
|
||||
// mod ls;
|
||||
// mod update;
|
||||
// mod upload;
|
||||
// mod install;
|
||||
// mod download;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct FileId(pub uuid::Uuid);
|
||||
|
||||
@@ -23,6 +16,10 @@ pub struct FileId(pub uuid::Uuid);
|
||||
/// the enum branch as well
|
||||
macro_rules! define_actions_enum {
|
||||
($(($mod:ident, $act:ident)),+$(,)?) => {
|
||||
$(
|
||||
mod $mod;
|
||||
)*
|
||||
|
||||
#[derive(::serde::Serialize, ::serde::Deserialize, Clone, Debug)]
|
||||
#[serde(tag = "cmd_type")]
|
||||
pub enum Actions {
|
||||
@@ -32,17 +29,34 @@ macro_rules! define_actions_enum {
|
||||
impl Actions {
|
||||
#[cfg(feature = "server")]
|
||||
fn render_internal(&self, data: String) -> AnyView {
|
||||
match self {
|
||||
$(
|
||||
Actions::$act(action) => {
|
||||
let Ok(data) = serde_json::from_str(&data) else {
|
||||
return view! {
|
||||
<p>"The command results in the database are corrupted"</p>
|
||||
}.into_any();
|
||||
};
|
||||
action.render_data(data).into_any()
|
||||
},
|
||||
)*
|
||||
let res: Result<Result<String, String>, _> = serde_json::from_str(&data);
|
||||
|
||||
match res {
|
||||
Ok(Ok(v)) => match self {
|
||||
$(
|
||||
Actions::$act(action) => {
|
||||
let Ok(data) = serde_json::from_str(&v) else {
|
||||
return view! {
|
||||
<p>"The command results in the database are corrupted"</p>
|
||||
}.into_any();
|
||||
};
|
||||
action.render_data(data).into_any()
|
||||
},
|
||||
)*
|
||||
},
|
||||
Ok(Err(e)) => view! {
|
||||
<details>
|
||||
<summary>
|
||||
"While running the command, an error occured:"
|
||||
</summary>
|
||||
<pre>
|
||||
{e}
|
||||
</pre>
|
||||
</details>
|
||||
}.into_any(),
|
||||
Err(_) => view! {
|
||||
<p>"The command results in the database are corrupted"</p>
|
||||
}.into_any()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +70,31 @@ macro_rules! define_actions_enum {
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "beacon")]
|
||||
async fn execute_internal<'a, T, S>(
|
||||
&self,
|
||||
parameters: &Parameters,
|
||||
adapter: &'a T,
|
||||
client: &'a hyper_util::client::legacy::Client<S, http_body_util::Full<bytes::Bytes>>
|
||||
) -> Result<Result<String, String>, BeaconError<T::Error>>
|
||||
where
|
||||
T: 'a + BeaconAdapter,
|
||||
S: hyper_util::client::legacy::connect::Connect + Clone + Send + Sync + 'static
|
||||
{
|
||||
match self {
|
||||
$(
|
||||
Actions::$act(action) => {
|
||||
Ok(action
|
||||
.execute(parameters, adapter, client)
|
||||
.await
|
||||
.and_then(|v| serde_json::to_string(&v)
|
||||
.map_err(Into::into))
|
||||
.map_err(|e| format!("beacon command error: {e:?}")))
|
||||
},
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(
|
||||
@@ -65,9 +104,25 @@ macro_rules! define_actions_enum {
|
||||
}
|
||||
}
|
||||
)*
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
pub const ACTION_BUILDERS: &'static [&'static (dyn ActionBuilder + Send + Sync)] = &[
|
||||
$(
|
||||
&ActionBuilderImpl::<$mod::$act>::new(),
|
||||
)*
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
define_actions_enum! {
|
||||
(exec, Exec),
|
||||
// (ls, Ls),
|
||||
// (update, Update),
|
||||
// (upload, Upload),
|
||||
// (install, Install),
|
||||
// (download, Download),
|
||||
}
|
||||
|
||||
#[cfg(feature = "server-ssr")]
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum BuildActionError {
|
||||
@@ -79,22 +134,13 @@ pub enum BuildActionError {
|
||||
Json(#[from] serde_json::Error)
|
||||
}
|
||||
|
||||
define_actions_enum! {
|
||||
(exec, Exec),
|
||||
// (ls, Ls),
|
||||
// (update, Update),
|
||||
// (upload, Upload),
|
||||
// (install, Install),
|
||||
// (download, Download),
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Action for Actions {
|
||||
const REQ_VERSION: Version = Version::new(2, 0);
|
||||
const REQ_OS: Option< &'static str> = None;
|
||||
const REQ_FIELDS: &'static[(&'static str, &'static str,Option< &'static str>)] = &[];
|
||||
|
||||
type ActionData = String;
|
||||
type ActionData = Result<String, String>;
|
||||
#[cfg(feature = "server-ssr")]
|
||||
type BuilderData = Self;
|
||||
|
||||
@@ -124,31 +170,10 @@ impl Action for Actions {
|
||||
T: 'a + BeaconAdapter,
|
||||
S: hyper_util::client::legacy::connect::Connect + Clone + Send + Sync + 'static
|
||||
{
|
||||
macro_rules! match_arm {
|
||||
($cmd:expr) => {
|
||||
$cmd
|
||||
.execute(parameters, adapter, client)
|
||||
.await
|
||||
.and_then(|v| serde_json::to_string(&v)
|
||||
.map_err(Into::into))
|
||||
}
|
||||
}
|
||||
match self {
|
||||
Actions::Exec(e) => match_arm!(e),
|
||||
}
|
||||
self.execute_internal(parameters, adapter, client).await
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
pub const ACTION_BUILDERS: &'static [&'static (dyn ActionBuilder + Send + Sync)] = &[
|
||||
&ActionBuilderImpl::<exec::Exec>::new(),
|
||||
//&ActionBuilderImpl::<ls::Ls>::new(),
|
||||
//&ActionBuilderImpl::<update::Update>::new(),
|
||||
//&ActionBuilderImpl::<upload::Upload>::new(),
|
||||
//&ActionBuilderImpl::<install::Install>::new(),
|
||||
//&ActionBuilderImpl::<download::Download>::new(),
|
||||
];
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait Action: Serialize + for<'a> Deserialize<'a> {
|
||||
const REQ_VERSION: Version;
|
||||
|
||||
Reference in New Issue
Block a user