Skip to content

Commit

Permalink
fix(pcloud,seafile): use get_basename and get_parent (#4020)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoslo authored Jan 19, 2024
1 parent 980f25b commit 76bbb3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 2 additions & 4 deletions core/src/services/pcloud/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,12 @@ impl PcloudCore {
pub async fn upload_file(&self, path: &str, bs: Bytes) -> Result<Response<IncomingAsyncBody>> {
let path = build_abs_path(&self.root, path);

let paths: Vec<&str> = path.split('/').collect();
let name = paths[paths.len() - 1];
let path = path.replace(&format!("/{}", name), "");
let (name, path) = (get_basename(&path), get_parent(&path).trim_end_matches('/'));

let url = format!(
"{}/uploadfile?path=/{}&filename={}&username={}&password={}",
self.endpoint,
percent_encode_path(&path),
percent_encode_path(path),
percent_encode_path(name),
self.username,
self.password
Expand Down
10 changes: 6 additions & 4 deletions core/src/services/seafile/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ impl SeafileWriter {
#[async_trait]
impl oio::OneShotWrite for SeafileWriter {
async fn write_once(&self, bs: &dyn oio::WriteBuf) -> Result<()> {
let path = build_abs_path(&self.core.root, &self.path);
let bs = oio::ChunkedBytes::from_vec(bs.vectored_bytes(bs.remaining()));

let upload_url = self.core.get_upload_url().await?;

let req = Request::post(upload_url);

let paths = path.split('/').collect::<Vec<&str>>();
let filename = paths[paths.len() - 1];
let relative_path = path.replace(filename, "");
let (filename, relative_path) = if self.path.ends_with('/') {
("", build_abs_path(&self.core.root, &self.path))
} else {
let (filename, relative_path) = (get_basename(&self.path), get_parent(&self.path));
(filename, build_abs_path(&self.core.root, relative_path))
};

let file_part = FormDataPart::new("file")
.header(
Expand Down

0 comments on commit 76bbb3f

Please sign in to comment.