cloud_disk_sync/utils/
account.rs

1use crate::config::{AccountConfig, ConfigManager};
2use std::collections::HashMap;
3
4pub fn find_account_id(config_manager: &ConfigManager, id_or_name: &str) -> Option<String> {
5    find_account_id_internal(config_manager.get_accounts(), id_or_name)
6}
7
8pub fn find_account_id_internal(
9    accounts: &HashMap<String, AccountConfig>,
10    id_or_name: &str,
11) -> Option<String> {
12    if accounts.contains_key(id_or_name) {
13        return Some(id_or_name.to_string());
14    }
15    for acc in accounts.values() {
16        if acc.name == id_or_name {
17            return Some(acc.id.clone());
18        }
19    }
20    None
21}