Added icarus_envy #140
Generated
+9
-1
@@ -730,8 +730,8 @@ version = "0.2.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"common-multipart-rfc7578",
|
||||
"dotenvy",
|
||||
"futures",
|
||||
"icarus_envy",
|
||||
"icarus_meta",
|
||||
"icarus_models",
|
||||
"serde",
|
||||
@@ -748,6 +748,14 @@ dependencies = [
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icarus_envy"
|
||||
version = "0.2.0"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.2.0#3ee8c1e573ba9637769aa0538d2c11335e39ed9f"
|
||||
dependencies = [
|
||||
"dotenvy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icarus_meta"
|
||||
version = "0.1.30"
|
||||
|
||||
+1
-1
@@ -18,9 +18,9 @@ futures = { version = "0.3.31" }
|
||||
uuid = { version = "1.16.0", features = ["v4", "serde"] }
|
||||
sqlx = { version = "0.8.5", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
||||
time = { version = "0.3.41", features = ["formatting", "macros", "parsing", "serde"] }
|
||||
dotenvy = { version = "0.15.7" }
|
||||
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.1.30" }
|
||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.3" }
|
||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.2.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
common-multipart-rfc7578 = { version = "0.7.0" }
|
||||
|
||||
@@ -508,7 +508,7 @@ pub mod endpoint {
|
||||
let song_id = payload.song_id;
|
||||
match crate::callers::song::song_db::get_song(&pool, &song_id).await {
|
||||
Ok(song) => {
|
||||
let directory = crate::environment::get_root_directory().await.unwrap();
|
||||
let directory = icarus_envy::environment::get_root_directory().await;
|
||||
let dir = std::path::Path::new(&directory);
|
||||
|
||||
// TODO: Make this random and the file extension should not be hard coded
|
||||
|
||||
+1
-1
@@ -770,7 +770,7 @@ pub mod endpoint {
|
||||
let mut song = payload.to_song();
|
||||
song.filename =
|
||||
song.generate_filename(icarus_models::types::MusicTypes::FlacExtension, true);
|
||||
song.directory = crate::environment::get_root_directory().await.unwrap();
|
||||
song.directory = icarus_envy::environment::get_root_directory().await;
|
||||
|
||||
match song_queue::get_data(&pool, &payload.song_queue_id).await {
|
||||
Ok(data) => {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
pub async fn get_db_url() -> String {
|
||||
dotenvy::dotenv().ok();
|
||||
std::env::var(crate::keys::DBURL).expect(crate::keys::error::ERROR)
|
||||
}
|
||||
|
||||
pub async fn get_root_directory() -> Result<String, std::env::VarError> {
|
||||
dotenvy::dotenv().ok();
|
||||
std::env::var(crate::keys::ROOT_DIRECTORY)
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
pub const DBURL: &str = "DATABASE_URL";
|
||||
pub const ROOT_DIRECTORY: &str = "ROOT_DIRECTORY";
|
||||
|
||||
pub mod error {
|
||||
pub const ERROR: &str = "DATABASE_URL must be set in .env";
|
||||
}
|
||||
+9
-22
@@ -1,6 +1,4 @@
|
||||
pub mod callers;
|
||||
pub mod environment;
|
||||
pub mod keys;
|
||||
|
||||
pub mod db {
|
||||
|
||||
@@ -11,7 +9,7 @@ pub mod db {
|
||||
}
|
||||
|
||||
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let database_url = crate::environment::get_db_url().await;
|
||||
let database_url = icarus_envy::environment::get_db_url().await;
|
||||
println!("Database url: {:?}", database_url);
|
||||
|
||||
PgPoolOptions::new()
|
||||
@@ -166,26 +164,23 @@ mod tests {
|
||||
mod db_mgr {
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::keys;
|
||||
|
||||
pub const LIMIT: usize = 6;
|
||||
|
||||
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
dotenvy::dotenv().ok();
|
||||
let tm_db_url = crate::environment::get_db_url().await;
|
||||
let tm_db_url = icarus_envy::environment::get_db_url().await;
|
||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||
sqlx::PgPool::connect_with(tm_options).await
|
||||
}
|
||||
|
||||
pub async fn generate_db_name() -> String {
|
||||
let db_name =
|
||||
get_database_name().unwrap() + &"_" + &uuid::Uuid::new_v4().to_string()[..LIMIT];
|
||||
let db_name = get_database_name().await.unwrap()
|
||||
+ &"_"
|
||||
+ &uuid::Uuid::new_v4().to_string()[..LIMIT];
|
||||
db_name
|
||||
}
|
||||
|
||||
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
dotenvy::dotenv().ok();
|
||||
let db_url = crate::environment::get_db_url().await;
|
||||
let db_url = icarus_envy::environment::get_db_url().await;
|
||||
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
||||
sqlx::PgPool::connect_with(options).await
|
||||
}
|
||||
@@ -211,12 +206,10 @@ mod tests {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||
dotenvy::dotenv().ok(); // Load .env file if it exists
|
||||
|
||||
match std::env::var(keys::DBURL) {
|
||||
Ok(database_url) => {
|
||||
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let database_url = icarus_envy::environment::get_db_url().await;
|
||||
let parsed_url = url::Url::parse(&database_url)?;
|
||||
|
||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||
match parsed_url
|
||||
.path_segments()
|
||||
@@ -230,12 +223,6 @@ mod tests {
|
||||
Err("Error parsing".into())
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
// DATABASE_URL environment variable not found
|
||||
Err("Error parsing".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod init {
|
||||
|
||||
Reference in New Issue
Block a user