mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
standardize result type for sideload progress
This commit is contained in:
@@ -12,7 +12,7 @@ use itertools::Itertools;
|
|||||||
use models::VersionString;
|
use models::VersionString;
|
||||||
use reqwest::header::{HeaderMap, CONTENT_LENGTH};
|
use reqwest::header::{HeaderMap, CONTENT_LENGTH};
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use rpc_toolkit::yajrc::RpcError;
|
use rpc_toolkit::yajrc::{GenericRpcMethod, RpcError};
|
||||||
use rpc_toolkit::HandlerArgs;
|
use rpc_toolkit::HandlerArgs;
|
||||||
use rustyline_async::ReadlineEvent;
|
use rustyline_async::ReadlineEvent;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -202,11 +202,12 @@ pub async fn sideload(
|
|||||||
use axum::extract::ws::Message;
|
use axum::extract::ws::Message;
|
||||||
async move {
|
async move {
|
||||||
if let Err(e) = async {
|
if let Err(e) = async {
|
||||||
|
type RpcResponse = rpc_toolkit::yajrc::RpcResponse::<GenericRpcMethod<&'static str, (), FullProgress>>;
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
res = async {
|
res = async {
|
||||||
while let Some(progress) = progress_listener.next().await {
|
while let Some(progress) = progress_listener.next().await {
|
||||||
ws.send(Message::Text(
|
ws.send(Message::Text(
|
||||||
serde_json::to_string(&Ok::<_, ()>(progress))
|
serde_json::to_string(&RpcResponse::from_result::<RpcError>(Ok(progress)))
|
||||||
.with_kind(ErrorKind::Serialization)?,
|
.with_kind(ErrorKind::Serialization)?,
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
@@ -217,7 +218,7 @@ pub async fn sideload(
|
|||||||
err = err_recv => {
|
err = err_recv => {
|
||||||
if let Ok(e) = err {
|
if let Ok(e) = err {
|
||||||
ws.send(Message::Text(
|
ws.send(Message::Text(
|
||||||
serde_json::to_string(&Err::<(), _>(e))
|
serde_json::to_string(&RpcResponse::from_result::<RpcError>(Err(e)))
|
||||||
.with_kind(ErrorKind::Serialization)?,
|
.with_kind(ErrorKind::Serialization)?,
|
||||||
))
|
))
|
||||||
.await
|
.await
|
||||||
@@ -406,14 +407,18 @@ pub async fn cli_install(
|
|||||||
|
|
||||||
let mut progress = FullProgress::new();
|
let mut progress = FullProgress::new();
|
||||||
|
|
||||||
|
type RpcResponse = rpc_toolkit::yajrc::RpcResponse<
|
||||||
|
GenericRpcMethod<&'static str, (), FullProgress>,
|
||||||
|
>;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
msg = ws.next() => {
|
msg = ws.next() => {
|
||||||
if let Some(msg) = msg {
|
if let Some(msg) = msg {
|
||||||
if let Message::Text(t) = msg.with_kind(ErrorKind::Network)? {
|
if let Message::Text(t) = msg.with_kind(ErrorKind::Network)? {
|
||||||
progress =
|
progress =
|
||||||
serde_json::from_str::<Result<_, RpcError>>(&t)
|
serde_json::from_str::<RpcResponse>(&t)
|
||||||
.with_kind(ErrorKind::Deserialization)??;
|
.with_kind(ErrorKind::Deserialization)?.result?;
|
||||||
bar.update(&progress);
|
bar.update(&progress);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user