feat: v1.7.14, support auto compress exts

This commit is contained in:
2024-09-22 01:09:16 +08:00
parent ac727f082e
commit 568022e655
5 changed files with 32 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
use std::env;
use rust_util::{debugging, util_env, warning};
use rust_util::util_env as rust_util_env;
use rust_util::{debugging, util_env, warning};
use crate::consts;
@@ -12,6 +12,7 @@ pub const TINY_ENCRYPT_ENV_USE_DIALOGUER: &str = "TINY_ENCRYPT_USE_DIALOGUER";
pub const TINY_ENCRYPT_ENV_PIN: &str = "TINY_ENCRYPT_PIN";
pub const TINY_ENCRYPT_ENV_KEY_ID: &str = "TINY_ENCRYPT_KEY_ID";
pub const TINY_ENCRYPT_ENV_AUTO_SELECT_KEY_IDS: &str = "TINY_ENCRYPT_AUTO_SELECT_KEY_IDS";
pub const TINY_ENCRYPT_EVN_AUTO_COMPRESS_EXTS: &str = "TINY_ENCRYPT_AUTO_COMPRESS_EXTS";
pub const TINY_ENCRYPT_ENV_GPG_COMMAND: &str = "TINY_ENCRYPT_GPG_COMMAND";
pub const TINY_ENCRYPT_ENV_NO_DEFAULT_PIN_HINT: &str = "TINY_ENCRYPT_NO_DEFAULT_PIN_HINT";
pub const TINY_ENCRYPT_ENV_PIN_ENTRY: &str = "TINY_ENCRYPT_PIN_ENTRY";
@@ -47,9 +48,11 @@ pub fn get_pin_entry() -> Option<String> {
}
pub fn get_auto_select_key_ids() -> Option<Vec<String>> {
env::var(TINY_ENCRYPT_ENV_AUTO_SELECT_KEY_IDS).ok().map(|key_ids| {
key_ids.split(',').map(ToString::to_string).collect::<Vec<_>>()
})
get_env_with_split(TINY_ENCRYPT_ENV_AUTO_SELECT_KEY_IDS)
}
pub fn get_auto_compress_file_exts() -> Option<Vec<String>> {
get_env_with_split(TINY_ENCRYPT_EVN_AUTO_COMPRESS_EXTS)
}
pub fn get_default_compress() -> Option<bool> {
@@ -67,3 +70,11 @@ pub fn get_no_default_pin_hint() -> bool {
pub fn get_use_dialoguer() -> bool {
rust_util_env::is_env_on(TINY_ENCRYPT_ENV_USE_DIALOGUER)
}
fn get_env_with_split(env_name: &str) -> Option<Vec<String>> {
let val = env::var(env_name).ok();
debugging!("Environment variable {} = {:?}", env_name, &val);
val.map(|env_values| {
env_values.split(',').map(ToString::to_string).collect::<Vec<_>>()
})
}