feat: add osssendfile-rs

This commit is contained in:
2024-08-21 23:42:32 +08:00
parent 589ffd47cc
commit f3275a5421
3 changed files with 1812 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
use clap::Parser;
use rust_util::{opt_result, opt_value_result, util_file, XResult};
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct OssSendFileConfig {
endpoint: String,
bucket: String,
token: String,
oidc: OidcConfig,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
struct OidcConfig {
sub: String,
client_id: String,
client_secret: String,
}
#[derive(Debug, Parser)]
#[command(name = "osssendfile-rs")]
#[command(about = "OSS send file Rust edition", long_about = None)]
struct OssSendFileArgs {
/// Config file, default location: ~/.jssp/config/osssendfile.json
#[arg(long)]
config: Option<String>,
/// Do not encrypt
#[arg(long)]
noenc: bool,
/// Do remove source file
#[arg(long)]
removesourcefile: bool,
/// JWK
#[arg(long)]
jwk: Option<String>,
/// Upload file path
#[arg(long)]
file: PathBuf,
/// File name, default use local file name
#[arg(long)]
filename: Option<String>,
/// Keywords
#[arg(long)]
keywords: Option<String>,
}
fn main() -> XResult<()> {
let args = OssSendFileArgs::parse();
let oss_send_file_config = load_config(&args.config)?;
println!("{:?}", args);
println!("{:?}", oss_send_file_config);
// TODO ...
Ok(())
}
fn load_config(config: &Option<String>) -> XResult<OssSendFileConfig> {
let config_file_opt = util_file::read_config(
config.clone(),
&["~/.jssp/config/osssendfile.json".to_string()],
);
let config_file = opt_value_result!(config_file_opt, "Config file not found.");
let config = opt_result!(
fs::read_to_string(&config_file), "Read file: {:?} failed: {}", config_file);
let oss_send_config: OssSendFileConfig = opt_result!(
serde_json::from_str(&config), "Parse file: {:?} failed: {}", config_file);
Ok(oss_send_config)
}