cleanup: strip comments, extract constants, DRY shared helpers across adapters + infra-wiring
- strip all comments except WHY workaround notes (3 remain) - remove all #[allow(dead_code)]; fix via _prefix rename - extract named constants: JWT time units, token types, default config values, jellyfin fallback bitrate - DRY: move serialize_enum_as_string, content_type_str, parse_content_type, parse_genres_blob to adapter-common - sqlite+postgres library.rs use shared helpers instead of local copies - sqlite+postgres channel.rs use shared serialize_enum_as_string - remove dead `let _ = ext` in scanner.rs
This commit is contained in:
@@ -11,7 +11,6 @@ use domain::MediaItemId;
|
||||
use crate::config::LocalFilesConfig;
|
||||
use crate::scanner::{scan_dir, LocalFileItem};
|
||||
|
||||
/// Encode a rel-path string into a URL-safe, padding-free base64 MediaItemId.
|
||||
pub fn encode_id(rel_path: &str) -> MediaItemId {
|
||||
use base64::Engine as _;
|
||||
MediaItemId::new(
|
||||
@@ -19,7 +18,6 @@ pub fn encode_id(rel_path: &str) -> MediaItemId {
|
||||
)
|
||||
}
|
||||
|
||||
/// Decode a MediaItemId back to a relative path string.
|
||||
pub fn decode_id(id: &MediaItemId) -> Option<String> {
|
||||
use base64::Engine as _;
|
||||
let bytes = base64::engine::general_purpose::URL_SAFE_NO_PAD
|
||||
@@ -28,11 +26,6 @@ pub fn decode_id(id: &MediaItemId) -> Option<String> {
|
||||
String::from_utf8(bytes).ok()
|
||||
}
|
||||
|
||||
/// In-memory (+ SQLite-backed) index of local video files.
|
||||
///
|
||||
/// On startup the index is populated from the SQLite cache so the provider can
|
||||
/// serve requests immediately. A background task calls `rescan()` to pick up
|
||||
/// any changes on disk and write them back to the cache.
|
||||
pub struct LocalIndex {
|
||||
items: Arc<RwLock<HashMap<MediaItemId, LocalFileItem>>>,
|
||||
pub root_dir: PathBuf,
|
||||
@@ -41,7 +34,6 @@ pub struct LocalIndex {
|
||||
}
|
||||
|
||||
impl LocalIndex {
|
||||
/// Create the index, immediately loading persisted entries from SQLite.
|
||||
pub async fn new(
|
||||
config: &LocalFilesConfig,
|
||||
pool: sqlx::SqlitePool,
|
||||
@@ -57,7 +49,6 @@ impl LocalIndex {
|
||||
idx
|
||||
}
|
||||
|
||||
/// Load previously scanned items from SQLite (instant on startup).
|
||||
async fn load_from_db(&self) {
|
||||
#[derive(sqlx::FromRow)]
|
||||
struct Row {
|
||||
@@ -107,10 +98,6 @@ impl LocalIndex {
|
||||
}
|
||||
}
|
||||
|
||||
/// Scan the filesystem for video files and rebuild the index.
|
||||
///
|
||||
/// Returns the number of items found. Called on startup (background task)
|
||||
/// and via `POST /files/rescan`.
|
||||
pub async fn rescan(&self) -> u32 {
|
||||
info!(
|
||||
"Local files [{}]: scanning {:?}",
|
||||
@@ -119,7 +106,6 @@ impl LocalIndex {
|
||||
let new_items = scan_dir(&self.root_dir).await;
|
||||
let count = new_items.len() as u32;
|
||||
|
||||
// Swap in-memory map.
|
||||
{
|
||||
let mut map = self.items.write().await;
|
||||
map.clear();
|
||||
@@ -129,7 +115,6 @@ impl LocalIndex {
|
||||
}
|
||||
}
|
||||
|
||||
// Persist to SQLite.
|
||||
if let Err(e) = self.save_to_db(&new_items).await {
|
||||
error!("Failed to persist local files index: {}", e);
|
||||
}
|
||||
@@ -142,7 +127,6 @@ impl LocalIndex {
|
||||
}
|
||||
|
||||
async fn save_to_db(&self, items: &[LocalFileItem]) -> Result<(), sqlx::Error> {
|
||||
// Rebuild the table in one transaction, scoped to this provider.
|
||||
let mut tx = self.pool.begin().await?;
|
||||
|
||||
sqlx::query("DELETE FROM local_files_index WHERE provider_id = ?")
|
||||
@@ -189,7 +173,6 @@ impl LocalIndex {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Return unique top-level directories as collection names.
|
||||
pub async fn collections(&self) -> Vec<String> {
|
||||
let map = self.items.read().await;
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
|
||||
Reference in New Issue
Block a user