Compare commits
3 Commits
release-20
...
release-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09a4c69282 | ||
|
|
a877e0c393 | ||
|
|
fd65df2962 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -8,3 +8,9 @@ backend.log
|
||||
.runner
|
||||
.env
|
||||
backend/.env
|
||||
*.db
|
||||
*.db-shm
|
||||
*.db-wal
|
||||
*.sqlite
|
||||
*.sqlite-shm
|
||||
*.sqlite-wal
|
||||
|
||||
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -3761,6 +3761,7 @@ dependencies = [
|
||||
"struct-patch",
|
||||
"thiserror 2.0.18",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"utoipa",
|
||||
]
|
||||
|
||||
|
||||
@@ -44,6 +44,6 @@ tower_governor = "0.8.0"
|
||||
governor = "0.10.4"
|
||||
|
||||
# Leptos
|
||||
leptos = { version = "0.8.15", features = ["nightly"] }
|
||||
leptos = { version = "0.8.15", features = ["nightly", "msgpack"] }
|
||||
leptos_axum = { version = "0.8.7" }
|
||||
jsonwebtoken = "9"
|
||||
@@ -41,7 +41,8 @@ pub fn Setup() -> impl IntoView {
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Setup failed: {:?}", e);
|
||||
error.1.set(Some("Kurulum sırasında bir hata oluştu".to_string()));
|
||||
// Hatanın sadece mesaj kısmını almaya çalışalım, yoksa full struct basılabilir
|
||||
error.1.set(Some(format!("Hata: {}", e)));
|
||||
loading.1.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ struct-patch = "0.5"
|
||||
rmp-serde = "1.3"
|
||||
bytes = "1"
|
||||
http = "1"
|
||||
tracing = "0.1"
|
||||
|
||||
# Leptos 0.8.7
|
||||
leptos = { version = "0.8.15", features = ["nightly", "msgpack"] }
|
||||
|
||||
@@ -28,9 +28,18 @@ impl Db {
|
||||
}
|
||||
|
||||
async fn run_migrations(&self) -> Result<()> {
|
||||
sqlx::migrate!("./migrations").run(&self.pool).await?;
|
||||
tracing::info!("Starting database migrations...");
|
||||
match sqlx::migrate!("./migrations").run(&self.pool).await {
|
||||
Ok(_) => {
|
||||
tracing::info!("Database migrations completed successfully.");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Database migration failed: {}", e);
|
||||
Err(e.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- User Operations ---
|
||||
|
||||
|
||||
@@ -24,9 +24,19 @@ pub struct SetupStatus {
|
||||
pub async fn get_setup_status() -> Result<SetupStatus, ServerFnError> {
|
||||
use crate::DbContext;
|
||||
|
||||
let db_context = use_context::<DbContext>().ok_or_else(|| ServerFnError::new("DB Context missing"))?;
|
||||
tracing::info!("Checking setup status...");
|
||||
let db_context = use_context::<DbContext>().ok_or_else(|| {
|
||||
tracing::error!("DB Context missing in GetSetupStatus");
|
||||
ServerFnError::new("DB Context missing")
|
||||
})?;
|
||||
|
||||
let has_users = db_context.db.has_users().await
|
||||
.map_err(|e| ServerFnError::new(format!("DB error: {}", e)))?;
|
||||
.map_err(|e| {
|
||||
tracing::error!("DB error in GetSetupStatus: {}", e);
|
||||
ServerFnError::new(format!("DB error: {}", e))
|
||||
})?;
|
||||
|
||||
tracing::info!("Setup status: completed={}", has_users);
|
||||
|
||||
Ok(SetupStatus {
|
||||
completed: has_users,
|
||||
@@ -37,21 +47,33 @@ pub async fn get_setup_status() -> Result<SetupStatus, ServerFnError> {
|
||||
pub async fn setup(username: String, password: String) -> Result<(), ServerFnError> {
|
||||
use crate::DbContext;
|
||||
|
||||
let db_context = use_context::<DbContext>().ok_or_else(|| ServerFnError::new("DB Context missing"))?;
|
||||
tracing::info!("Attempting setup for user: {}", username);
|
||||
let db_context = use_context::<DbContext>().ok_or_else(|| {
|
||||
tracing::error!("DB Context missing in Setup");
|
||||
ServerFnError::new("DB Context missing")
|
||||
})?;
|
||||
|
||||
// Check if setup is already done
|
||||
let has_users = db_context.db.has_users().await.unwrap_or(false);
|
||||
if has_users {
|
||||
tracing::warn!("Setup attempt blocked: Setup already completed");
|
||||
return Err(ServerFnError::new("Setup already completed"));
|
||||
}
|
||||
|
||||
// Hash password (low cost for MIPS)
|
||||
let password_hash = bcrypt::hash(&password, 6)
|
||||
.map_err(|_| ServerFnError::new("Hashing error"))?;
|
||||
.map_err(|e| {
|
||||
tracing::error!("Hashing error: {}", e);
|
||||
ServerFnError::new("Hashing error")
|
||||
})?;
|
||||
|
||||
db_context.db.create_user(&username, &password_hash).await
|
||||
.map_err(|e| ServerFnError::new(format!("DB error: {}", e)))?;
|
||||
.map_err(|e| {
|
||||
tracing::error!("Failed to create user: {}", e);
|
||||
ServerFnError::new(format!("DB error: {}", e))
|
||||
})?;
|
||||
|
||||
tracing::info!("Setup completed successfully for user: {}", username);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
BIN
vibetorrent.db
BIN
vibetorrent.db
Binary file not shown.
Reference in New Issue
Block a user