diff --git a/src/modes/server.rs b/src/modes/server.rs index 70dba2d..476a4f5 100644 --- a/src/modes/server.rs +++ b/src/modes/server.rs @@ -1,13 +1,13 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use axum::{ extract::{Path, Query, State}, http::{HeaderMap, StatusCode}, response::{Html, Json}, - routing::{delete, get, put}, + routing::get, Router, }; use clap::Command; -use log::{debug, info, warn}; +use log::{info, warn}; use serde::{Deserialize, Serialize}; use serde_json::json; use std::collections::HashMap; @@ -18,8 +18,7 @@ use std::sync::Arc; use tokio::sync::Mutex; use tower_http::cors::CorsLayer; -use crate::db::{self, Item, Tag, Meta}; -use crate::modes::common::{format_size, OutputFormat}; +use crate::db; use crate::Args; #[derive(Debug, Clone)] @@ -78,7 +77,7 @@ struct TagsQuery { } pub fn mode_server( - cmd: &mut Command, + _cmd: &mut Command, args: &Args, conn: &mut rusqlite::Connection, data_path: PathBuf, @@ -97,14 +96,17 @@ pub fn mode_server( async fn run_server( config: ServerConfig, - conn: &mut rusqlite::Connection, + _conn: &mut rusqlite::Connection, data_dir: PathBuf, ) -> Result<()> { info!("Starting REST HTTP server on {}", config.address); - // Move connection into Arc> for sharing across async tasks + // Create a new database connection for the server // Note: This is a simplified approach. In production, you'd want a connection pool - let db_conn = Arc::new(Mutex::new(std::mem::replace(conn, unsafe { std::mem::zeroed() }))); + let mut db_path = data_dir.clone(); + db_path.push("keep-1.db"); + let new_conn = crate::db::open(db_path)?; + let db_conn = Arc::new(Mutex::new(new_conn)); let state = AppState { db: db_conn,