52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
// 1.Find provider by name
|
|
// 2.execute provider
|
|
use url::form_urlencoded;
|
|
use rocket::http::uri::Query;
|
|
|
|
use core::time;
|
|
use std::time::SystemTime;
|
|
|
|
use super::guards::APIProviderRequest;
|
|
use crate::api::guards;
|
|
use crate::errors::AutoDecryptError;
|
|
use crate::main;
|
|
use crate::orm::structures::{BaseProviderRecord};
|
|
use crate::orm::types::{AuthMethod, RecordStates};
|
|
use crate::services::providers::{ConsentMethode, ProviderAction, Providers, ActionType};
|
|
use crate::app_config::CONFIG;
|
|
|
|
|
|
|
|
|
|
|
|
pub(super) fn get_query_value(query: &Option<Query>, query_key: &str) -> Option<String> {
|
|
if let Some(query) = query {
|
|
// Parse the query string manually
|
|
for (key, value) in form_urlencoded::parse(query.as_bytes()) {
|
|
if key == query_key {
|
|
return Some(value.to_string());
|
|
}
|
|
}
|
|
}
|
|
None
|
|
}
|
|
|
|
|
|
pub(super) async fn execute_action(action: &Providers, key: Option<&str>) -> Result<String, AutoDecryptError> {
|
|
let exec_action = match &action.execution_action {
|
|
ActionType::ForigneAction(forigne_action) => {
|
|
&forigne_action.to_executable_action(key)? as &dyn ProviderAction
|
|
},
|
|
_ => &action.execution_action as &dyn ProviderAction,
|
|
};
|
|
|
|
exec_action.execute().await
|
|
}
|
|
|
|
pub(super) fn find_provider_by_name(name: &str) -> Option<(&String, &Providers)> {
|
|
CONFIG
|
|
.wait()
|
|
.providers
|
|
.iter()
|
|
.find(|(serv_name, _)| *serv_name == name)
|
|
} |