156 lines
3.8 KiB
Rust
156 lines
3.8 KiB
Rust
use std::{
|
|
cmp::{max, min},
|
|
io::{stdout, Write},
|
|
path::{Path, PathBuf},
|
|
sync::Arc,
|
|
};
|
|
|
|
use aws_config::{environment::region, BehaviorVersion, Region, SdkConfig};
|
|
use aws_sdk_s3::{
|
|
config::Credentials, operation::upload_part, primitives::ByteStream, types::CompletedPart,
|
|
};
|
|
use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
|
|
use aws_smithy_types::byte_stream::Length;
|
|
use clap::{Parser, Subcommand};
|
|
use constants::REFRESH_TOKEN;
|
|
use human_bytes::human_bytes;
|
|
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
|
|
use rakuten_drive_cui::RakutenDriveClient;
|
|
use tokio::{fs::File, io::BufReader, sync::Mutex};
|
|
use types::response::ListFilesResponseFile;
|
|
use util::*;
|
|
|
|
mod client;
|
|
mod constants;
|
|
mod types;
|
|
mod util;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(version, about, long_about=None)]
|
|
struct Args {
|
|
#[command(subcommand)]
|
|
command: Commands,
|
|
}
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
enum Commands {
|
|
#[clap(about = "List files")]
|
|
List {
|
|
/// Parent folder path
|
|
#[clap(short, long)]
|
|
prefix: Option<String>,
|
|
},
|
|
#[clap(about = "Upload file")]
|
|
Upload {
|
|
file: PathBuf,
|
|
|
|
/// Parent folder path
|
|
#[clap(short, long)]
|
|
prefix: Option<String>,
|
|
|
|
/// Upload folder recursively
|
|
#[clap(short, long)]
|
|
recursive: bool,
|
|
|
|
/// Send fake file size to server (byte)
|
|
#[clap(short, long)]
|
|
fake_size: Option<u64>,
|
|
},
|
|
#[clap(about = "Download file")]
|
|
Download {
|
|
path: String,
|
|
|
|
/// Parent folder path
|
|
#[clap(long)]
|
|
prefix: Option<String>,
|
|
},
|
|
#[clap(about = "Move file")]
|
|
Move {
|
|
// Source file path
|
|
path: String,
|
|
|
|
// Destination folder path
|
|
dest: String,
|
|
},
|
|
#[clap(about = "Delete file")]
|
|
Delete {
|
|
path: String,
|
|
|
|
/// Delete folder recursively
|
|
#[clap(long)]
|
|
recursive: bool,
|
|
},
|
|
#[clap(about = "Make directory")]
|
|
Mkdir {
|
|
name: String,
|
|
|
|
/// Path to create directory
|
|
#[clap(long)]
|
|
path: Option<String>,
|
|
},
|
|
#[clap(about = "Copy file")]
|
|
Copy {
|
|
/// Source file path
|
|
src: String,
|
|
|
|
/// Destination file directory
|
|
dest: String,
|
|
},
|
|
#[clap(about = "Rename file")]
|
|
Rename {
|
|
/// Target file path
|
|
path: String,
|
|
|
|
/// New file name
|
|
name: String,
|
|
},
|
|
#[clap(about = "Print file detail")]
|
|
Info { path: String },
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
let args = Args::parse();
|
|
|
|
let client = RakutenDriveClient::try_new(REFRESH_TOKEN.to_string()).await?;
|
|
|
|
match &args.command {
|
|
Commands::List { prefix } => {
|
|
client.list(prefix.as_deref()).await.unwrap();
|
|
}
|
|
Commands::Upload {
|
|
file,
|
|
prefix,
|
|
recursive,
|
|
fake_size,
|
|
} => {
|
|
client
|
|
.upload(file, prefix.as_deref(), *recursive, *fake_size)
|
|
.await.unwrap();
|
|
}
|
|
Commands::Download { path, prefix } => {
|
|
client.download(path.as_str(), prefix.as_deref()).await.unwrap();
|
|
}
|
|
Commands::Move { path, dest } => {
|
|
client.move_file(path, dest).await.unwrap();
|
|
}
|
|
Commands::Delete { path, recursive } => {
|
|
client.delete(path, recursive).await.unwrap();
|
|
}
|
|
Commands::Mkdir { name, path } => {
|
|
client.mkdir(name, path.as_deref()).await.unwrap();
|
|
}
|
|
Commands::Copy { src: _, dest: _ } => {
|
|
todo!("Copy");
|
|
}
|
|
Commands::Rename { path, name } => {
|
|
client.rename(path, name).await.unwrap();
|
|
}
|
|
Commands::Info { path } => {
|
|
client.info(path).await.unwrap();
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|