Skip to content

Commit

Permalink
support create_dir
Browse files Browse the repository at this point in the history
Signed-off-by: suyanhanx <[email protected]>
  • Loading branch information
suyanhanx committed Jul 6, 2023
1 parent 9b4c2b4 commit 5bdd0b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/services/dropbox/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,25 @@ impl Accessor for DropboxBackend {
ma.set_scheme(Scheme::Dropbox)
.set_root(&self.core.root)
.set_capability(Capability {
stat: true,

read: true,

write: true,

create_dir: true,

delete: true,

..Default::default()
});
ma
}

async fn create_dir(&self, path: &str, args: OpCreateDir) -> Result<RpCreateDir> {

}

async fn read(&self, path: &str, _args: OpRead) -> Result<(RpRead, Self::Reader)> {
let resp = self.core.dropbox_get(path).await?;
let status = resp.status();
Expand Down
21 changes: 21 additions & 0 deletions core/src/services/dropbox/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ impl DropboxCore {
self.client.send(request).await
}

pub async fn dropbox_create_folder(&self, path: &str) -> Result<Response<IncomingAsyncBody>>{
let url = "https://api.dropboxapi.com/2/files/create_folder_v2".to_string();
let args = DropboxCreateFolderArgs {
path: build_rooted_abs_path(&self.root, path),
};

let bs = Bytes::from(serde_json::to_string(&args).map_err(new_json_serialize_error)?);

let request = self
.build_auth_header(Request::post(&url))
.header(header::CONTENT_TYPE, "application/json")
.body(AsyncBody::Bytes(bs))
.map_err(new_request_build_error)?;
self.client.send(request).await
}

pub async fn dropbox_get_metadata(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
let url = "https://api.dropboxapi.com/2/files/get_metadata".to_string();
let args = DropboxMetadataArgs {
Expand Down Expand Up @@ -157,6 +173,11 @@ struct DropboxDeleteArgs {
path: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
struct DropboxCreateFolderArgs {
path: String,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
struct DropboxMetadataArgs {
include_deleted: bool,
Expand Down

0 comments on commit 5bdd0b1

Please sign in to comment.