mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-05-07 06:43:29 -04:00
Refactor: Return bytes from core client action
Co-authored-by: ijamespine <ijamespine@me.com>
This commit is contained in:
@@ -58,7 +58,7 @@ pub async fn run(ctx: &Context, cmd: FileCmd) -> Result<()> {
|
||||
if let Err(errors) = input.validate() {
|
||||
anyhow::bail!(errors.join("; "))
|
||||
}
|
||||
ctx.core.action(&input).await?;
|
||||
let _bytes = ctx.core.action(&input).await?;
|
||||
println!("Copy request submitted");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ async fn main() -> Result<()> {
|
||||
if let Err(errors) = input.validate() {
|
||||
anyhow::bail!(errors.join("; "));
|
||||
}
|
||||
core.action(&input).await?;
|
||||
let _bytes = core.action(&input).await?;
|
||||
println!("Copy request submitted");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ impl MutationRoot {
|
||||
let mut input = sd_core::ops::files::copy::input::FileCopyInput::default();
|
||||
input.sources = sources.into_iter().map(Into::into).collect();
|
||||
input.destination = destination.into();
|
||||
state
|
||||
let _bytes = state
|
||||
.core
|
||||
.action(&input)
|
||||
.await
|
||||
|
||||
@@ -23,7 +23,7 @@ impl CoreClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn action<A>(&self, action: &A) -> Result<()>
|
||||
pub async fn action<A>(&self, action: &A) -> Result<Vec<u8>>
|
||||
where
|
||||
A: Wire + Serialize,
|
||||
{
|
||||
@@ -37,7 +37,7 @@ impl CoreClient {
|
||||
.await;
|
||||
match resp {
|
||||
Ok(r) => match r {
|
||||
DaemonResponse::Ok(_) => Ok(()),
|
||||
DaemonResponse::Ok(bytes) => Ok(bytes),
|
||||
DaemonResponse::Error(e) => Err(anyhow::anyhow!(e)),
|
||||
other => Err(anyhow::anyhow!(format!("unexpected response: {:?}", other))),
|
||||
},
|
||||
|
||||
@@ -103,6 +103,16 @@ impl JobHandle {
|
||||
}
|
||||
}
|
||||
|
||||
// Serialize JobHandle as its JobId for wire transport
|
||||
impl serde::Serialize for JobHandle {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
self.id.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
/// Update events from a job
|
||||
#[derive(Debug)]
|
||||
pub enum JobUpdate {
|
||||
|
||||
@@ -113,9 +113,10 @@ pub fn handle_library_action<A>(
|
||||
where
|
||||
A: crate::infra::action::LibraryAction + 'static,
|
||||
A::Input: DeserializeOwned + 'static,
|
||||
A::Output: serde::Serialize + 'static,
|
||||
{
|
||||
use bincode::config::standard;
|
||||
use bincode::serde::decode_from_slice;
|
||||
use bincode::serde::{decode_from_slice, encode_to_vec};
|
||||
(async move {
|
||||
let input: A::Input = decode_from_slice(&payload, standard())
|
||||
.map_err(|e| e.to_string())?
|
||||
@@ -123,11 +124,11 @@ where
|
||||
let action = A::from_input(input)?;
|
||||
let manager = crate::infra::action::manager::ActionManager::new(core.context.clone());
|
||||
let library_id = session.current_library_id.ok_or("No library selected")?;
|
||||
manager
|
||||
let out = manager
|
||||
.dispatch_library(library_id, action)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(Vec::new())
|
||||
encode_to_vec(&out, standard()).map_err(|e| e.to_string())
|
||||
})
|
||||
.boxed_local()
|
||||
}
|
||||
@@ -141,20 +142,21 @@ pub fn handle_core_action<A>(
|
||||
where
|
||||
A: crate::infra::action::CoreAction + 'static,
|
||||
A::Input: DeserializeOwned + 'static,
|
||||
A::Output: serde::Serialize + 'static,
|
||||
{
|
||||
use bincode::config::standard;
|
||||
use bincode::serde::decode_from_slice;
|
||||
use bincode::serde::{decode_from_slice, encode_to_vec};
|
||||
(async move {
|
||||
let input: A::Input = decode_from_slice(&payload, standard())
|
||||
.map_err(|e| e.to_string())?
|
||||
.0;
|
||||
let action = A::from_input(input)?;
|
||||
let manager = crate::infra::action::manager::ActionManager::new(core.context.clone());
|
||||
manager
|
||||
let out = manager
|
||||
.dispatch_core(action)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
Ok(Vec::new())
|
||||
encode_to_vec(&out, standard()).map_err(|e| e.to_string())
|
||||
})
|
||||
.boxed_local()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user