Formatting and cleanup
This commit is contained in:
@@ -16,16 +16,8 @@ pub struct EnvironmentConfiguration {
|
||||
pub api_session_ttl: u64,
|
||||
pub valkey_host: String,
|
||||
pub valkey_port: u16,
|
||||
pub minio_root_user: String,
|
||||
pub minio_root_password: String,
|
||||
pub minio_host: String,
|
||||
pub minio_port: u16,
|
||||
pub minio_port_internal: u16,
|
||||
pub data_dir_path: Option<String>,
|
||||
pub force_register: bool,
|
||||
pub default_api_key: String,
|
||||
pub default_server: Option<String>,
|
||||
pub default_user: Option<String>,
|
||||
pub force_command_register: bool,
|
||||
}
|
||||
|
||||
impl EnvironmentConfiguration {
|
||||
@@ -57,25 +49,11 @@ impl EnvironmentConfiguration {
|
||||
.unwrap_or_else(|_| "6379".to_string())
|
||||
.parse()
|
||||
.unwrap_or(6379),
|
||||
minio_root_user: env::var("MINIO_ROOT_USER")?,
|
||||
minio_root_password: env::var("MINIO_ROOT_PASSWORD")?,
|
||||
minio_host: env::var("MINIO_HOST").unwrap_or_else(|_| "localhost".to_string()),
|
||||
minio_port: env::var("MINIO_PORT")
|
||||
.unwrap_or_else(|_| "9000".to_string())
|
||||
.parse()
|
||||
.unwrap_or(9000),
|
||||
minio_port_internal: env::var("MINIO_PORT_INTERNAL")
|
||||
.unwrap_or_else(|_| "9001".to_string())
|
||||
.parse()
|
||||
.unwrap_or(9001),
|
||||
data_dir_path: env::var("DATA_DIR_PATH").ok().filter(|s| !s.is_empty()),
|
||||
force_register: env::var("FORCE_REGISTER")
|
||||
force_command_register: env::var("FORCE_COMMAND_REGISTER")
|
||||
.ok()
|
||||
.map(|v| v.to_lowercase() == "true")
|
||||
.unwrap_or(false),
|
||||
default_api_key: env::var("DEFAULT_API_KEY").unwrap_or_default(),
|
||||
default_server: env::var("DEFAULT_SERVER").ok().filter(|s| !s.is_empty()),
|
||||
default_user: env::var("DEFAULT_USER").ok().filter(|s| !s.is_empty()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
mod model;
|
||||
|
||||
pub use model::*;
|
||||
@@ -1,74 +0,0 @@
|
||||
use crate::error::Result;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
const TABLE_NAME: &str = "messages";
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
|
||||
pub struct MessageCache {
|
||||
pub id: String,
|
||||
pub guild_id: i64,
|
||||
pub channel_id: i64,
|
||||
pub author_id: i64,
|
||||
pub created: i64,
|
||||
pub model: String,
|
||||
pub request: String,
|
||||
pub response: String,
|
||||
pub request_tags: Vec<String>,
|
||||
pub response_tags: Vec<String>,
|
||||
}
|
||||
|
||||
impl MessageCache {
|
||||
pub async fn insert(&self) -> Result<()> {
|
||||
let pool = crate::data::pool();
|
||||
sqlx::query(&format!(
|
||||
"INSERT INTO {} (
|
||||
id,
|
||||
guild_id,
|
||||
channel_id,
|
||||
author_id,
|
||||
created,
|
||||
model,
|
||||
request,
|
||||
response,
|
||||
request_tags,
|
||||
response_tags
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10
|
||||
)",
|
||||
TABLE_NAME
|
||||
))
|
||||
.bind(&self.id)
|
||||
.bind(self.guild_id)
|
||||
.bind(self.channel_id)
|
||||
.bind(self.author_id)
|
||||
.bind(self.created)
|
||||
.bind(&self.model)
|
||||
.bind(&self.request)
|
||||
.bind(&self.response)
|
||||
.bind(&self.request_tags)
|
||||
.bind(&self.response_tags)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn find(
|
||||
guild_id: i64,
|
||||
channel_id: i64,
|
||||
author_id: i64,
|
||||
limit: i64,
|
||||
) -> Result<Vec<MessageCache>> {
|
||||
let pool = crate::data::pool();
|
||||
let messages = sqlx::query_as::<_, MessageCache>(&format!(
|
||||
"SELECT * FROM {} WHERE guild_id = $1 AND channel_id = $2 AND author_id = $3 ORDER BY created ASC LIMIT $4",
|
||||
TABLE_NAME
|
||||
))
|
||||
.bind(guild_id)
|
||||
.bind(channel_id)
|
||||
.bind(author_id)
|
||||
.bind(limit)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
Ok(messages)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ pub mod events;
|
||||
mod executable_query;
|
||||
pub mod guilds;
|
||||
pub mod insert;
|
||||
pub mod messages;
|
||||
pub mod query;
|
||||
pub mod update;
|
||||
use crate::config::EnvironmentConfiguration;
|
||||
|
||||
Reference in New Issue
Block a user