add: change database to postgres
This commit is contained in:
parent
24d9f17bd4
commit
187508b8f3
15 changed files with 647 additions and 471 deletions
106
src/config.rs
Normal file
106
src/config.rs
Normal file
|
@ -0,0 +1,106 @@
|
|||
use oiseau::config::{Configuration, DatabaseConfig};
|
||||
use pathbufd::PathBufD;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tetratto_shared::hash::random_id;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
/// The name of the site. Shown in the UI.
|
||||
#[serde(default = "default_name")]
|
||||
pub name: String,
|
||||
/// The (CSS) theme color of the site. Shown in the UI.
|
||||
#[serde(default = "default_theme_color")]
|
||||
pub theme_color: String,
|
||||
/// The URL of the Tetratto host associated with this instance.
|
||||
#[serde(default = "default_tetratto")]
|
||||
pub tetratto: String,
|
||||
/// The slug of the instance's information page.
|
||||
///
|
||||
/// Should be the pathname WITHOUT the leading slash.
|
||||
#[serde(default = "default_what_page_slug")]
|
||||
pub what_page_slug: String,
|
||||
/// The username of the handler account in charge of this instance on the
|
||||
/// linked Tetratto host.
|
||||
#[serde(default = "default_tetratto_handler_account_username")]
|
||||
pub tetratto_handler_account_username: String,
|
||||
/// Database configuration.
|
||||
#[serde(default = "default_database")]
|
||||
pub database: DatabaseConfig,
|
||||
/// Real IP header (for reverse proxy).
|
||||
#[serde(default = "default_real_ip_header")]
|
||||
pub real_ip_header: String,
|
||||
/// The master password which is allowed to do anything without password checks.
|
||||
pub master_pass: String,
|
||||
}
|
||||
|
||||
fn default_name() -> String {
|
||||
"Fluffle".to_string()
|
||||
}
|
||||
|
||||
fn default_theme_color() -> String {
|
||||
"#a3b3ff".to_string()
|
||||
}
|
||||
|
||||
fn default_tetratto() -> String {
|
||||
"https://tetratto.com".to_string()
|
||||
}
|
||||
|
||||
fn default_what_page_slug() -> String {
|
||||
"what".to_string()
|
||||
}
|
||||
|
||||
fn default_tetratto_handler_account_username() -> String {
|
||||
"fluffle".to_string()
|
||||
}
|
||||
|
||||
fn default_database() -> DatabaseConfig {
|
||||
DatabaseConfig::default()
|
||||
}
|
||||
|
||||
fn default_real_ip_header() -> String {
|
||||
"CF-Connecting-IP".to_string()
|
||||
}
|
||||
|
||||
impl Configuration for Config {
|
||||
fn db_config(&self) -> DatabaseConfig {
|
||||
self.database.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: default_name(),
|
||||
theme_color: default_theme_color(),
|
||||
tetratto: default_tetratto(),
|
||||
what_page_slug: default_what_page_slug(),
|
||||
tetratto_handler_account_username: default_tetratto_handler_account_username(),
|
||||
database: default_database(),
|
||||
real_ip_header: default_real_ip_header(),
|
||||
master_pass: random_id(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Read the configuration file.
|
||||
pub fn read() -> Self {
|
||||
toml::from_str(
|
||||
&match std::fs::read_to_string(PathBufD::current().join("fluffle.toml")) {
|
||||
Ok(x) => x,
|
||||
Err(_) => {
|
||||
let x = Config::default();
|
||||
|
||||
std::fs::write(
|
||||
PathBufD::current().join("fluffle.toml"),
|
||||
&toml::to_string_pretty(&x).expect("failed to serialize config"),
|
||||
)
|
||||
.expect("failed to write config");
|
||||
|
||||
return x;
|
||||
}
|
||||
},
|
||||
)
|
||||
.expect("failed to deserialize config")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue