1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
//! This module implements a subset of the nodes DRACOON API.
//! Documentation can be found here: <https://download.dracoon.com/api/swagger-ui/index.html?configUrl=/api/spec_v4/swagger-config#/nodes>
pub use self::{
models::*,
rooms::models::*,
};
use super::{auth::errors::DracoonClientError, models::ListAllParams};
use async_trait::async_trait;
use std::io::Write;
use tokio::io::{AsyncRead, BufReader};
pub mod download;
pub mod folders;
pub mod models;
pub mod nodes;
pub mod rooms;
pub mod upload;
/// This trait provides methods to manage nodes.
/// Specifically, there's a method to obtain a node for a given path and
/// all relevant methods to list nodes (get, search), move, copy and deleted nodes.
///
/// To download a node, use the [Download] trait.
/// To upload a node, use the [Upload] trait.
/// To manage rooms, use the [Rooms] trait.
/// To manage folders, use the [Folders] trait.
#[async_trait]
pub trait Nodes {
/// Returns a list of nodes.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Nodes, nodes::{NodesFilter, NodesSortBy}, models::{ListAllParams, SortOrder}};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let nodes = dracoon.get_nodes(None, None, None).await.unwrap();
///
/// // get all nodes for a parent
/// let nodes = dracoon.get_nodes(Some(123), None, None).await.unwrap();
///
/// // get all nodes visible as room manager / admin
/// let nodes = dracoon.get_nodes(None, Some(true), None).await.unwrap();
///
/// // use filtering and sorting
/// let params = ListAllParams::builder()
/// .with_filter(NodesFilter::is_file())
/// .with_filter(NodesFilter::name_contains("foo"))
/// .with_sort(NodesSortBy::name(SortOrder::Desc))
/// .build();
///
/// let nodes = dracoon.get_nodes(None, None, Some(params)).await.unwrap();
/// # }
/// ```
async fn get_nodes(
&self,
parent_id: Option<u64>,
room_manager: Option<bool>,
params: Option<ListAllParams>,
) -> Result<NodeList, DracoonClientError>;
/// Searches for a node via given path.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Nodes, nodes::{NodesFilter, NodesSortBy}, models::{ListAllParams, SortOrder}};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let node = dracoon.get_node_from_path("/foo/bar").await.unwrap();
/// match node {
/// Some(node) => println!("Found node: {}", node.name),
/// None => println!("Node not found"),
/// };
/// # }
/// ```
async fn get_node_from_path(&self, path: &str) -> Result<Option<Node>, DracoonClientError>;
/// Searches for nodes by search string.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Nodes, nodes::{NodesSearchFilter, NodesSearchSortBy}, models::{ListAllParams, SortOrder}};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// // search for nodes ("*" is wildcard)
/// let nodes = dracoon.search_nodes("foo", None, None, None).await.unwrap();
///
/// // search for nodes in a parent
/// let nodes = dracoon.search_nodes("foo", Some(123), None, None).await.unwrap();
///
/// // search for nodes in a parent with a depth level (-1 is full tree)
/// let nodes = dracoon.search_nodes("foo", Some(123), Some(1), None).await.unwrap();
///
/// // use filtering and sorting
/// let params = ListAllParams::builder()
/// .with_filter(NodesSearchFilter::is_file())
/// .with_filter(NodesSearchFilter::size_greater_equals(100))
/// .with_sort(NodesSearchSortBy::name(SortOrder::Desc))
/// .build();
/// let nodes = dracoon.search_nodes("foo", None, None, Some(params)).await.unwrap();
/// # }
/// ```
async fn search_nodes(
&self,
search_string: &str,
parent_id: Option<u64>,
depth_level: Option<i8>,
params: Option<ListAllParams>,
) -> Result<NodeList, DracoonClientError>;
/// Returns a node by id.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Nodes};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let node = dracoon.get_node(123).await.unwrap();
/// # }
/// ```
async fn get_node(&self, node_id: u64) -> Result<Node, DracoonClientError>;
/// Deletes a node by id.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Nodes};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// dracoon.delete_node(123).await.unwrap();
/// # }
/// ```
async fn delete_node(&self, node_id: u64) -> Result<(), DracoonClientError>;
/// Deletes multiple nodes by ids.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Nodes};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let node_ids = vec![123, 456];
/// dracoon.delete_nodes(node_ids.into()).await.unwrap();
/// # }
/// ```
async fn delete_nodes(&self, req: DeleteNodesRequest) -> Result<(), DracoonClientError>;
/// Move nodes to a target parent node (folder or room).
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Nodes};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let node_ids = vec![123, 456];
/// dracoon.move_nodes(node_ids.into(), 789).await.unwrap();
/// # }
/// ```
async fn move_nodes(
&self,
req: TransferNodesRequest,
target_parent_id: u64,
) -> Result<Node, DracoonClientError>;
/// Copy nodes to a target parent node (folder or room).
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Nodes};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let node_ids = vec![123, 456];
/// dracoon.copy_nodes(node_ids.into(), 789).await.unwrap();
/// # }
/// ```
async fn copy_nodes(
&self,
req: TransferNodesRequest,
target_parent_id: u64,
) -> Result<Node, DracoonClientError>;
}
#[async_trait]
pub trait Folders {
/// Creates a folder in the provided parent room.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Folders, nodes::CreateFolderRequest};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let folder = CreateFolderRequest::builder("My Folder", 123)
/// .with_classification(1)
/// .with_notes("My notes")
/// .build();
/// let folder = dracoon.create_folder(folder).await.unwrap();
/// # }
/// ```
async fn create_folder(&self, req: CreateFolderRequest) -> Result<Node, DracoonClientError>;
/// Updates a folder with given params by id.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Folders, nodes::UpdateFolderRequest};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let update = UpdateFolderRequest::builder()
/// .with_name("My Folder")
/// .with_classification(2)
/// .build();
/// dracoon.update_folder(123, update).await.unwrap();
/// # }
/// ```
async fn update_folder(
&self,
folder_id: u64,
req: UpdateFolderRequest,
) -> Result<Node, DracoonClientError>;
}
/// This trait provides methods to manage rooms.
///
/// - Create a room
/// - Update a room
/// - Configure a room
/// - Encrypt a room
/// - Get groups of a room
/// - Add groups to a room
/// - Delete groups from a room
/// - Get users of a room
/// - Add users to a room
/// - Delete users from a room
///
/// To delete a room, use the `delete_node` method from the `Nodes` trait.
#[async_trait]
pub trait Rooms {
/// Creates a room.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Rooms, nodes::CreateRoomRequest};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let room = CreateRoomRequest::builder("My Room")
/// .with_parent_id(123)
/// .with_classification(1)
/// .build();
/// let room = dracoon.create_room(room).await.unwrap();
/// # }
/// ```
async fn create_room(
&self,
create_room_req: CreateRoomRequest,
) -> Result<Node, DracoonClientError>;
/// Updates a room by id.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Rooms, nodes::UpdateRoomRequest};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let room = UpdateRoomRequest::builder()
/// .with_name("My new Room")
/// .build();
/// let room = dracoon.update_room(123, room).await.unwrap();
/// # }
/// ```
async fn update_room(
&self,
room_id: u64,
update_room_req: UpdateRoomRequest,
) -> Result<Node, DracoonClientError>;
/// Configures a room by id.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Rooms, nodes::ConfigRoomRequest};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let room = ConfigRoomRequest::builder()
/// .with_inherit_permissions(true)
/// .with_recycle_bin_retention_period(30)
/// .build();
/// let room = dracoon.config_room(123, room).await.unwrap();
/// # }
/// ```
async fn config_room(
&self,
room_id: u64,
config_room_req: ConfigRoomRequest,
) -> Result<Node, DracoonClientError>;
/// Encrypts a room by id.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Rooms, nodes::EncryptRoomRequest};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let encryption = EncryptRoomRequest::builder(true)
/// .try_with_data_room_rescue_key("Secret123")
/// .unwrap()
/// .build();
/// let room = dracoon.encrypt_room(123, encryption).await.unwrap();
/// # }
/// ```
async fn encrypt_room(
&self,
room_id: u64,
encrypt_room_req: EncryptRoomRequest,
) -> Result<Node, DracoonClientError>;
/// Gets groups of a room by id with optional params.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Rooms};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let groups = dracoon.get_room_groups(123, None).await.unwrap();
/// # }
/// ```
async fn get_room_groups(
&self,
room_id: u64,
params: Option<ListAllParams>,
) -> Result<RoomGroupList, DracoonClientError>;
/// Updates room groups by id.
/// Gets groups of a room by id with optional params.
/// ```no_run
/// # use dco3::{Dracoon, OAuth2Flow, Rooms, nodes::{RoomGroupsAddBatchRequestItem, NodePermissions}};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
///
/// // add a a list of updates
/// let group_updates = vec![RoomGroupsAddBatchRequestItem::new(123, NodePermissions::new_with_read_permissions(), None)];
/// dracoon.update_room_groups(123, group_updates.into()).await.unwrap();
/// # }
/// ```
async fn update_room_groups(
&self,
room_id: u64,
room_groups_update_req: RoomGroupsAddBatchRequest,
) -> Result<(), DracoonClientError>;
/// Deletes room groups by id.
/// Gets groups of a room by id with optional params.
/// ```no_run
/// # use dco3::{Dracoon, OAuth2Flow, Rooms};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// // You can use a vec
/// let group_ids = vec![1, 2, 3];
/// dracoon.delete_room_groups(123, group_ids.into()).await.unwrap();
/// # }
/// ```
async fn delete_room_groups(
&self,
room_id: u64,
room_groups_del_req: RoomGroupsDeleteBatchRequest,
) -> Result<(), DracoonClientError>;
/// Gets users of a room by id with optional params.
/// Gets groups of a room by id with optional params.
/// ```no_run
/// # use dco3::{Dracoon, OAuth2Flow, Rooms};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// let users = dracoon.get_room_users(123, None).await.unwrap();
/// # }
/// ```
async fn get_room_users(
&self,
room_id: u64,
params: Option<ListAllParams>,
) -> Result<RoomUserList, DracoonClientError>;
/// Updates room users by id.
/// Gets groups of a room by id with optional params.
/// ```no_run
/// # use dco3::{Dracoon, OAuth2Flow, Rooms, nodes::{RoomUsersAddBatchRequestItem, NodePermissions}};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
///
/// // add a a list of updates
/// let user_updates = vec![RoomUsersAddBatchRequestItem::new(123, NodePermissions::new_with_read_permissions())];
/// dracoon.update_room_users(123, user_updates.into()).await.unwrap();
/// # }
/// ```
async fn update_room_users(
&self,
room_id: u64,
room_users_update_req: RoomUsersAddBatchRequest,
) -> Result<(), DracoonClientError>;
/// Deletes room users by id.
/// Gets groups of a room by id with optional params.
/// ```no_run
/// # use dco3::{Dracoon, OAuth2Flow, Rooms};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// // You can use a vec
/// let user_ids = vec![1, 2, 3];
/// dracoon.delete_room_users(123, user_ids.into()).await.unwrap();
/// # }
/// ```
async fn delete_room_users(
&self,
room_id: u64,
room_users_del_req: RoomUsersDeleteBatchRequest,
) -> Result<(), DracoonClientError>;
}
/// This trait represents the download functionality and provides
/// a signle method to download a stream of bytes to a writer.
/// This rquires a mutable reference to the client because the download method
/// needs to be able to check for the secret and set it for the client if encryption is used.
#[async_trait]
pub trait Download {
/// Downloads a file (node) to the given writer buffer
/// Example
/// ```no_run
/// use dco3::{Dracoon, OAuth2Flow, Download, Nodes};
///
/// #[tokio::main]
/// async fn main() {
/// let client = Dracoon::builder()
/// .with_base_url("https://dracoon.team")
/// .with_client_id("client_id")
/// .with_client_secret("client_secret")
/// // if you do not pass a password, encrypted uploads will fail with an error
/// .with_encryption_password("encryption_password")
/// .build()
/// .unwrap()
/// .connect(OAuth2Flow::password_flow("username", "password"))
/// .await
/// .unwrap();
///
/// let node_id = 123u64;
///
/// let node = client.get_node(node_id).await.unwrap();
///
/// let mut writer = std::io::BufWriter::new(std::fs::File::create("test.txt").unwrap());
///
/// client.download(&node, &mut writer, None).await.unwrap();
///
/// // or with progress callback (boxed closure)
/// client.download(&node, &mut writer, Some(Box::new(|progress, total| {
/// println!("Download progress: {}", progress);
/// println!("File total: {}", total);
/// }))).await.unwrap();
/// }
/// ```
///
///
async fn download<'w>(
&'w self,
node: &Node,
writer: &'w mut (dyn Write + Send),
mut callback: Option<DownloadProgressCallback>,
) -> Result<(), DracoonClientError>;
}
/// This trait represents the upload functionality and provides
/// a single method to upload a stream of bytes by passing a buffered reader.
/// This rquires a mutable reference to the client because the upload method
/// needs to be able to check for the secret and set it for the client if encryption is used.
#[async_trait]
pub trait Upload<R: AsyncRead> {
/// Uploads a stream (buffered reader) with given file meta info to the given parent node
/// # Example
/// ```no_run
/// use dco3::{Dracoon, OAuth2Flow, Upload, Nodes, nodes::{FileMeta, UploadOptions, ResolutionStrategy}};
/// #[cfg(not(doctest))]
/// #[tokio::main]
/// async fn main() {
/// let client = Dracoon::builder()
/// .with_base_url("https://dracoon.team")
/// .with_client_id("client_id")
/// .with_client_secret("client_secret")
/// // if you do not pass a password, encrypted uploads will fail with an error
/// .with_encryption_password("encryption_password")
/// .build()
/// .unwrap()
/// .connect(OAuth2Flow::password_flow("username", "password"))
/// .await
/// .unwrap();
///
/// let file = tokio::fs::File::open("test.txt").await.unwrap();
/// let file_meta = FileMeta::builder()
/// .with_name("test.txt".into())
/// .with_size(123456)
/// .with_timestamp_modification("2020-01-01T00:00:00.000Z".parse().unwrap())
/// .build();
///
///
/// let parent_node_id = 123u64;
///
/// let parent_node = client.get_node(parent_node_id).await.unwrap();
///
/// let reader = tokio::io::BufReader::new(file);
///
/// let options = UploadOptions::builder()
/// .with_resolution_strategy(ResolutionStrategy::AutoRename)
/// .build();
///
/// let chunk_size = 1024 * 1024 * 10; // 10 MB - DEFAULT is 32 MB
///
/// client.upload(file_meta, &parent_node, options, reader, None, Some(chunk_size)).await.unwrap();
///
/// // or with progress callback (boxed closure)
/// let file = tokio::fs::File::open("test.txt").await.unwrap();
/// let file_meta = FileMeta::builder()
/// .with_name("test.txt".into())
/// .with_size(123456)
/// .with_timestamp_modification("2020-01-01T00:00:00.000Z".parse().unwrap())
/// .build();
/// let options = UploadOptions::builder()
/// .with_resolution_strategy(ResolutionStrategy::AutoRename)
/// .build();
/// let reader = tokio::io::BufReader::new(file);
/// client.upload(file_meta, &parent_node, options, reader, Some(Box::new(|progress, total| {
/// println!("Upload progress: {}", progress);
/// println!("File total: {}", total);
/// })), Some(chunk_size)).await.unwrap();
/// }
/// ```
///
///
async fn upload<'r>(
&'r self,
file_meta: FileMeta,
parent_node: &Node,
upload_options: UploadOptions,
mut reader: BufReader<R>,
mut callback: Option<UploadProgressCallback>,
chunk_size: Option<usize>,
) -> Result<Node, DracoonClientError>;
}