Skip to content

Commit

Permalink
complete error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ForgQi committed Jul 29, 2022
1 parent bcffbd9 commit 33e064a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ pub async fn upload(
// let line = line::kodo();
for video_path in video_path {
println!("{line:?}");
let video_file = VideoFile::new(video_path)?;
let video_file = VideoFile::new(video_path)
.with_context(|| format!("file {}", video_path.to_string_lossy()))?;
let total_size = video_file.total_size;
let file_name = video_file.file_name.clone();
let uploader = line.to_uploader(video_file);
Expand Down
14 changes: 9 additions & 5 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ impl<'a> Parcel<'a> {
}

pub async fn pre_upload<T: DeserializeOwned>(&self, login: &Client) -> Result<T> {
Ok(login
let response = login
.client
.get(format!(
"https://member.bilibili.com/preupload?{}",
self.line.query
))
.query(&self.params)
.send()
.await?
.json()
.await
.with_context(|| "Failed to pre_upload from")?)
.await?;
let full = response.bytes().await?;
Ok(serde_json::from_slice(&full).with_context(|| {
format!(
"Failed to pre_upload from {}",
String::from_utf8_lossy(&full)
)
})?)
}

pub async fn upload<F, S, B>(&self, client: &Client, limit: usize, progress: F) -> Result<Video>
Expand Down

0 comments on commit 33e064a

Please sign in to comment.