diff --git a/docker-compose.yml b/docker-compose.yml index b78cd2e..273d268 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,12 @@ services: typstdrive: build: . + container_name: typstdrive ports: - - "3000:3000" + - "3285:3000" + environment: + # This ensures the database is saved to your mounted volume + - DATABASE_URL=sqlite:/app/data/typstdrive.db?mode=rwc volumes: - - ./data:/app/data - restart: unless-stopped + - /media/blob/TeaNet/TypstDrive:/app/data + restart: unless-stopped \ No newline at end of file diff --git a/server/src/db.rs b/server/src/db.rs index fe8cf7f..f1f7d2c 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -2,9 +2,22 @@ use sqlx::sqlite::SqlitePoolOptions; use sqlx::{Pool, Sqlite}; pub async fn init_db() -> Pool { + let db_url = std::env::var("DATABASE_URL").unwrap_or_else(|_| "sqlite:typstdrive.db?mode=rwc".to_string()); + + // Ensure parent directory exists if there is one + if let Some(path) = db_url.strip_prefix("sqlite:") { + if let Some(path) = path.split('?').next() { + if let Some(parent) = std::path::Path::new(path).parent() { + if !parent.as_os_str().is_empty() { + let _ = std::fs::create_dir_all(parent); + } + } + } + } + let pool = SqlitePoolOptions::new() .max_connections(5) - .connect("sqlite:typstdrive.db?mode=rwc") + .connect(&db_url) .await .expect("Failed to create pool.");