This commit is contained in:
parent
a5629ea741
commit
0d3a772432
3 changed files with 20 additions and 20 deletions
|
@ -25,11 +25,12 @@ fuzzy-matcher = "0.3.7"
|
||||||
jm_client_core = { path = "../jm_client_core" }
|
jm_client_core = { path = "../jm_client_core" }
|
||||||
log = "0.4.11"
|
log = "0.4.11"
|
||||||
opener = "0.4.1"
|
opener = "0.4.1"
|
||||||
reqwest = { version = "0.10", features = ["stream"] }
|
reqwest = { version = "0.11", features = ["stream", "multipart"] }
|
||||||
serde_json = "1.0.60"
|
serde_json = "1.0.60"
|
||||||
structopt = "0.3.21"
|
structopt = "0.3.21"
|
||||||
term-table = "1.3.0"
|
term-table = "1.3.0"
|
||||||
term_size = "0.3.2"
|
term_size = "0.3.2"
|
||||||
tokio = { version = "0.2.23", features = ["macros", "fs", "process"] }
|
tokio = { version = "1.7.0", features = ["macros", "fs", "process", "rt-multi-thread"] }
|
||||||
|
tokio-util = { version = "0.6.7", features = ["codec"] }
|
||||||
url = "2.2.0"
|
url = "2.2.0"
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
use crate::util;
|
use crate::util;
|
||||||
use anyhow::{Result, bail};
|
use anyhow::{bail, Result};
|
||||||
use jm_client_core::{api::UpResp, JMClient};
|
use jm_client_core::{api::UpResp, JMClient};
|
||||||
use log::info;
|
use log::info;
|
||||||
use reqwest::{
|
use reqwest::multipart::{Form, Part};
|
||||||
multipart::{Form, Part},
|
use reqwest::Body;
|
||||||
Body,
|
use tokio::fs::File;
|
||||||
};
|
use tokio_util::codec::{BytesCodec, FramedRead};
|
||||||
use tokio::{fs::File, io::reader_stream};
|
|
||||||
|
|
||||||
pub async fn run(
|
pub async fn run(
|
||||||
client: &JMClient,
|
client: &JMClient,
|
||||||
|
@ -27,10 +26,13 @@ pub async fn run(
|
||||||
.text("token", token)
|
.text("token", token)
|
||||||
.part(
|
.part(
|
||||||
"file",
|
"file",
|
||||||
Part::stream(Body::wrap_stream(reader_stream({
|
Part::stream(Body::wrap_stream(FramedRead::new(
|
||||||
|
{
|
||||||
info!("Opening file {}", &path);
|
info!("Opening file {}", &path);
|
||||||
File::open(path).await?
|
File::open(path).await?
|
||||||
})))
|
},
|
||||||
|
BytesCodec::new(),
|
||||||
|
)))
|
||||||
.file_name(name),
|
.file_name(name),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -43,15 +45,12 @@ pub async fn run(
|
||||||
|
|
||||||
let res = if let Ok(res) = serde_json::from_slice::<UpResp>(bytes) {
|
let res = if let Ok(res) = serde_json::from_slice::<UpResp>(bytes) {
|
||||||
res
|
res
|
||||||
} else {
|
} else if let Ok(s) = std::str::from_utf8(bytes) {
|
||||||
if let Ok(s) = std::str::from_utf8(bytes) {
|
|
||||||
bail!("Server responded with unexpected response: {}", s);
|
bail!("Server responded with unexpected response: {}", s);
|
||||||
} else {
|
} else {
|
||||||
bail!("Server responded with invalid utf8 bytes: {:?}", bytes);
|
bail!("Server responded with invalid utf8 bytes: {:?}", bytes);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
println!("Server responded with code {}", status);
|
println!("Server responded with code {}", status);
|
||||||
|
|
||||||
if !open {
|
if !open {
|
||||||
|
|
|
@ -12,9 +12,9 @@ env_logger = "0.8.2"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
log = "0.4.11"
|
log = "0.4.11"
|
||||||
once_cell = "1.5.2"
|
once_cell = "1.5.2"
|
||||||
reqwest = "0.10.9"
|
reqwest = "0.11.3"
|
||||||
serde = { version = "1.0.117", features = ["derive"] }
|
serde = { version = "1.0.117", features = ["derive"] }
|
||||||
serde_json = "1.0.60"
|
serde_json = "1.0.60"
|
||||||
thiserror = "1.0.23"
|
thiserror = "1.0.23"
|
||||||
tokio = { version = "0.2.23", features = ["macros", "fs"] }
|
tokio = { version = "1.7.0", features = ["macros", "fs", "rt-multi-thread"] }
|
||||||
url = "2.2.0"
|
url = "2.2.0"
|
||||||
|
|
Loading…
Reference in a new issue