31 lines
786 B
Rust
31 lines
786 B
Rust
use serde::Deserialize;
|
|
|
|
#[derive(Debug, Default, Clone, Deserialize)]
|
|
pub struct Config {
|
|
/// Allowed tokens for access
|
|
pub allowed_tokens: Vec<String>,
|
|
/// Webhook Config
|
|
pub webhook: Option<Webhook>,
|
|
}
|
|
|
|
pub fn get_config() -> Config {
|
|
if let Ok(content) = std::fs::read_to_string("./config.toml") {
|
|
return toml::from_str(&content).unwrap();
|
|
}
|
|
|
|
Config::default()
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct Webhook {
|
|
pub item_below_minimum: Option<String>,
|
|
pub transaction_added: Option<String>,
|
|
pub transaction_consumed: Option<String>,
|
|
}
|
|
|
|
impl Webhook {
|
|
pub async fn send(url: &str, data: &serde_json::Value) {
|
|
let client = reqwest::Client::new();
|
|
client.post(url).json(data).send().await.unwrap();
|
|
}
|
|
}
|