mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-22 12:13:48 +01:00
escape database password as it may contain special characters
This commit is contained in:
parent
367190c39c
commit
e2d4aaa002
@ -13,7 +13,6 @@ default = []
|
||||
convert = ["dep:native-utils"]
|
||||
|
||||
[dependencies]
|
||||
async-std = { version = "1", features = ["attributes", "tokio1"] }
|
||||
serde_json = "1.0.96"
|
||||
native-utils = { path = "../", optional = true }
|
||||
indicatif = { version = "0.17.4", features = ["tokio"] }
|
||||
@ -21,6 +20,7 @@ tokio = { version = "1.28.2", features = ["full"] }
|
||||
futures = "0.3.28"
|
||||
serde_yaml = "0.9.21"
|
||||
serde = { version = "1.0.163", features = ["derive"] }
|
||||
urlencoding = "2.1.2"
|
||||
|
||||
[dependencies.sea-orm-migration]
|
||||
version = "0.11.0"
|
||||
|
@ -1,24 +1,29 @@
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use urlencoding::encode;
|
||||
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[cfg(feature = "convert")]
|
||||
mod vec_to_json;
|
||||
|
||||
#[async_std::main]
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let cwd = env::current_dir().unwrap();
|
||||
let yml = fs::File::open(cwd.join("../../.config/default.yml"))
|
||||
.expect("Unable to read '.config/default.yml'");
|
||||
let config: Config = serde_yaml::from_reader(yml).expect("Unable to parse");
|
||||
.expect("Failed to open '.config/default.yml'");
|
||||
let config: Config = serde_yaml::from_reader(yml).expect("Failed to parse yaml");
|
||||
|
||||
env::set_var(
|
||||
"DATABASE_URL",
|
||||
format!(
|
||||
"postgres://{}:{}@{}:{}/{}",
|
||||
config.db.user, config.db.pass, config.db.host, config.db.port, config.db.db
|
||||
config.db.user,
|
||||
encode(&config.db.pass),
|
||||
config.db.host,
|
||||
config.db.port,
|
||||
config.db.db,
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -222,7 +222,9 @@ export const db = new DataSource({
|
||||
|
||||
export async function initDb(force = false) {
|
||||
await nativeInitDatabase(
|
||||
`postgres://${config.db.user}:${config.db.pass}@${config.db.host}:${config.db.port}/${config.db.db}`,
|
||||
`postgres://${config.db.user}:${encodeURIComponent(config.db.pass)}@${
|
||||
config.db.host
|
||||
}:${config.db.port}/${config.db.db}`,
|
||||
);
|
||||
if (force) {
|
||||
if (db.isInitialized) {
|
||||
|
Loading…
Reference in New Issue
Block a user