mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2024-11-26 11:25:58 +03:00
Fix compiling
- I made some mistakes while checking my two previous PRs(Seems like I don't understand Rust that great after all). - Do the url encoding only on the password part, not only the whole URL. - Fix `temporary value dropped while borrowed` compile error.
This commit is contained in:
parent
af35fdb48e
commit
8826f6df8f
3 changed files with 27 additions and 17 deletions
|
@ -68,10 +68,8 @@ impl Connect for ConnectionOptions {
|
|||
async fn connect(self) -> DBResult<Self::Pool> {
|
||||
let pool = match self {
|
||||
Self::Fresh(fresh) => {
|
||||
let mut connect_options = sqlx::mysql::MySqlConnectOptions::from_str(
|
||||
&urlencoding::encode(&fresh.url),
|
||||
)
|
||||
.unwrap();
|
||||
let mut connect_options =
|
||||
sqlx::mysql::MySqlConnectOptions::from_str(&fresh.url).unwrap();
|
||||
if fresh.disable_logging {
|
||||
connect_options.disable_statement_logging();
|
||||
}
|
||||
|
|
|
@ -68,10 +68,8 @@ impl Connect for ConnectionOptions {
|
|||
async fn connect(self) -> DBResult<Self::Pool> {
|
||||
let pool = match self {
|
||||
Self::Fresh(fresh) => {
|
||||
let mut connect_options = sqlx::postgres::PgConnectOptions::from_str(
|
||||
&urlencoding::encode(&fresh.url),
|
||||
)
|
||||
.unwrap();
|
||||
let mut connect_options =
|
||||
sqlx::postgres::PgConnectOptions::from_str(&fresh.url).unwrap();
|
||||
if fresh.disable_logging {
|
||||
connect_options.disable_statement_logging();
|
||||
}
|
||||
|
|
|
@ -152,15 +152,26 @@ impl Settings {
|
|||
.expect("unable to set capatcha.enable_stats default config");
|
||||
|
||||
if let Ok(path) = env::var("MCAPTCHA_CONFIG") {
|
||||
let absolute_path =
|
||||
Path::new(&path).canonicalize().unwrap().to_str().unwrap();
|
||||
log::info!("{}", format!("Loading config file from {}", absolute_path));
|
||||
s.merge(File::with_name(absolute_path))?;
|
||||
let absolute_path = Path::new(&path).canonicalize().unwrap();
|
||||
log::info!(
|
||||
"{}",
|
||||
format!(
|
||||
"Loading config file from {}",
|
||||
absolute_path.to_str().unwrap()
|
||||
)
|
||||
);
|
||||
s.merge(File::with_name(absolute_path.to_str().unwrap()))?;
|
||||
} else if Path::new(CURRENT_DIR).exists() {
|
||||
let absolute_path = fs::canonicalize(CURRENT_DIR).unwrap().to_str().unwrap();
|
||||
log::info!("{}", format!("Loading config file from {}", absolute_path));
|
||||
let absolute_path = fs::canonicalize(CURRENT_DIR).unwrap();
|
||||
log::info!(
|
||||
"{}",
|
||||
format!(
|
||||
"Loading config file from {}",
|
||||
absolute_path.to_str().unwrap()
|
||||
)
|
||||
);
|
||||
// merging default config from file
|
||||
s.merge(File::with_name(absolute_path))?;
|
||||
s.merge(File::with_name(absolute_path.to_str().unwrap()))?;
|
||||
} else if Path::new(ETC).exists() {
|
||||
log::info!("{}", format!("Loading config file from {}", ETC));
|
||||
s.merge(File::with_name(ETC))?;
|
||||
|
@ -220,8 +231,11 @@ fn set_database_url(s: &mut Config) {
|
|||
r"postgres://{}:{}@{}:{}/{}",
|
||||
s.get::<String>("database.username")
|
||||
.expect("Couldn't access database username"),
|
||||
s.get::<String>("database.password")
|
||||
.expect("Couldn't access database password"),
|
||||
urlencoding::encode(
|
||||
s.get::<String>("database.password")
|
||||
.expect("Couldn't access database password")
|
||||
.as_str()
|
||||
),
|
||||
s.get::<String>("database.hostname")
|
||||
.expect("Couldn't access database hostname"),
|
||||
s.get::<String>("database.port")
|
||||
|
|
Loading…
Reference in a new issue