mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-02-18 17:39:46 +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> {
|
async fn connect(self) -> DBResult<Self::Pool> {
|
||||||
let pool = match self {
|
let pool = match self {
|
||||||
Self::Fresh(fresh) => {
|
Self::Fresh(fresh) => {
|
||||||
let mut connect_options = sqlx::mysql::MySqlConnectOptions::from_str(
|
let mut connect_options =
|
||||||
&urlencoding::encode(&fresh.url),
|
sqlx::mysql::MySqlConnectOptions::from_str(&fresh.url).unwrap();
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
if fresh.disable_logging {
|
if fresh.disable_logging {
|
||||||
connect_options.disable_statement_logging();
|
connect_options.disable_statement_logging();
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,10 +68,8 @@ impl Connect for ConnectionOptions {
|
||||||
async fn connect(self) -> DBResult<Self::Pool> {
|
async fn connect(self) -> DBResult<Self::Pool> {
|
||||||
let pool = match self {
|
let pool = match self {
|
||||||
Self::Fresh(fresh) => {
|
Self::Fresh(fresh) => {
|
||||||
let mut connect_options = sqlx::postgres::PgConnectOptions::from_str(
|
let mut connect_options =
|
||||||
&urlencoding::encode(&fresh.url),
|
sqlx::postgres::PgConnectOptions::from_str(&fresh.url).unwrap();
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
if fresh.disable_logging {
|
if fresh.disable_logging {
|
||||||
connect_options.disable_statement_logging();
|
connect_options.disable_statement_logging();
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,15 +152,26 @@ impl Settings {
|
||||||
.expect("unable to set capatcha.enable_stats default config");
|
.expect("unable to set capatcha.enable_stats default config");
|
||||||
|
|
||||||
if let Ok(path) = env::var("MCAPTCHA_CONFIG") {
|
if let Ok(path) = env::var("MCAPTCHA_CONFIG") {
|
||||||
let absolute_path =
|
let absolute_path = Path::new(&path).canonicalize().unwrap();
|
||||||
Path::new(&path).canonicalize().unwrap().to_str().unwrap();
|
log::info!(
|
||||||
log::info!("{}", format!("Loading config file from {}", absolute_path));
|
"{}",
|
||||||
s.merge(File::with_name(absolute_path))?;
|
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() {
|
} else if Path::new(CURRENT_DIR).exists() {
|
||||||
let absolute_path = fs::canonicalize(CURRENT_DIR).unwrap().to_str().unwrap();
|
let absolute_path = fs::canonicalize(CURRENT_DIR).unwrap();
|
||||||
log::info!("{}", format!("Loading config file from {}", absolute_path));
|
log::info!(
|
||||||
|
"{}",
|
||||||
|
format!(
|
||||||
|
"Loading config file from {}",
|
||||||
|
absolute_path.to_str().unwrap()
|
||||||
|
)
|
||||||
|
);
|
||||||
// merging default config from file
|
// 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() {
|
} else if Path::new(ETC).exists() {
|
||||||
log::info!("{}", format!("Loading config file from {}", ETC));
|
log::info!("{}", format!("Loading config file from {}", ETC));
|
||||||
s.merge(File::with_name(ETC))?;
|
s.merge(File::with_name(ETC))?;
|
||||||
|
@ -220,8 +231,11 @@ fn set_database_url(s: &mut Config) {
|
||||||
r"postgres://{}:{}@{}:{}/{}",
|
r"postgres://{}:{}@{}:{}/{}",
|
||||||
s.get::<String>("database.username")
|
s.get::<String>("database.username")
|
||||||
.expect("Couldn't access database username"),
|
.expect("Couldn't access database username"),
|
||||||
s.get::<String>("database.password")
|
urlencoding::encode(
|
||||||
.expect("Couldn't access database password"),
|
s.get::<String>("database.password")
|
||||||
|
.expect("Couldn't access database password")
|
||||||
|
.as_str()
|
||||||
|
),
|
||||||
s.get::<String>("database.hostname")
|
s.get::<String>("database.hostname")
|
||||||
.expect("Couldn't access database hostname"),
|
.expect("Couldn't access database hostname"),
|
||||||
s.get::<String>("database.port")
|
s.get::<String>("database.port")
|
||||||
|
|
Loading…
Add table
Reference in a new issue