feat: implement local-files feature with various enhancements and cleanup
This commit is contained in:
@@ -9,5 +9,5 @@ pub fn json_err(e: serde_json::Error) -> String {
|
||||
}
|
||||
|
||||
pub fn ok_json<T: serde::Serialize>(value: &T) -> String {
|
||||
serde_json::to_string(value).unwrap_or_else(|e| json_err(e))
|
||||
serde_json::to_string(value).unwrap_or_else(json_err)
|
||||
}
|
||||
|
||||
@@ -87,20 +87,19 @@ async fn main() -> anyhow::Result<()> {
|
||||
|
||||
#[cfg(feature = "local-files")]
|
||||
if let Some(dir) = std::env::var("LOCAL_FILES_DIR").ok().map(std::path::PathBuf::from) {
|
||||
if let k_core::db::DatabasePool::Sqlite(ref sqlite_pool) = db_pool {
|
||||
let base_url = std::env::var("BASE_URL")
|
||||
.unwrap_or_else(|_| "http://localhost:3000".to_string());
|
||||
let lf_cfg = infra::LocalFilesConfig {
|
||||
root_dir: dir,
|
||||
base_url,
|
||||
transcode_dir: None,
|
||||
cleanup_ttl_hours: 24,
|
||||
};
|
||||
let idx = Arc::new(infra::LocalIndex::new(&lf_cfg, sqlite_pool.clone()).await);
|
||||
let scan_idx = Arc::clone(&idx);
|
||||
tokio::spawn(async move { scan_idx.rescan().await; });
|
||||
registry.register("local", Arc::new(infra::LocalFilesProvider::new(idx, lf_cfg, None)));
|
||||
}
|
||||
let k_core::db::DatabasePool::Sqlite(ref sqlite_pool) = db_pool;
|
||||
let base_url = std::env::var("BASE_URL")
|
||||
.unwrap_or_else(|_| "http://localhost:3000".to_string());
|
||||
let lf_cfg = infra::LocalFilesConfig {
|
||||
root_dir: dir,
|
||||
base_url,
|
||||
transcode_dir: None,
|
||||
cleanup_ttl_hours: 24,
|
||||
};
|
||||
let idx = Arc::new(infra::LocalIndex::new(&lf_cfg, sqlite_pool.clone()).await);
|
||||
let scan_idx = Arc::clone(&idx);
|
||||
tokio::spawn(async move { scan_idx.rescan().await; });
|
||||
registry.register("local", Arc::new(infra::LocalFilesProvider::new(idx, lf_cfg, None)));
|
||||
}
|
||||
|
||||
if registry.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user