chore(qconnect): checkpoint current poc state

cx
This commit is contained in:
vicrodh committed 2026-03-13 17:28:05 -06:00
1 parent 6d20360dc3
commit de29f1e2e0
92 files changed
+3886 -2433

No files matched your search

+54 -51
View File
@@ -991,15 +991,21 @@ impl LibraryDatabase {
}
// Detect if this file is a Qobuz purchased download
let is_purchase: bool = self.conn
let is_purchase: bool = self
.conn
.query_row(
"SELECT COUNT(*) FROM downloaded_purchases WHERE file_path = ?1",
params![track.file_path],
|row| row.get::<_, i64>(0),
)
.unwrap_or(0) > 0;
.unwrap_or(0)
> 0;
let source = if is_purchase { "qobuz_purchase" } else { "user" };
let source = if is_purchase {
"qobuz_purchase"
} else {
"user"
};
self.conn
.execute(
@@ -1047,7 +1053,10 @@ impl LibraryDatabase {
pub fn get_track(&self, id: i64) -> Result<Option<LocalTrack>, LibraryError> {
let mut stmt = self
.conn
.prepare(&format!("SELECT {} FROM local_tracks WHERE id = ?", Self::TRACK_COLUMNS))
.prepare(&format!(
"SELECT {} FROM local_tracks WHERE id = ?",
Self::TRACK_COLUMNS
))
.map_err(|e| LibraryError::Database(e.to_string()))?;
stmt.query_row(params![id], |row| Self::row_to_track(row))
@@ -1059,7 +1068,10 @@ impl LibraryDatabase {
pub fn get_track_by_path(&self, path: &str) -> Result<Option<LocalTrack>, LibraryError> {
let mut stmt = self
.conn
.prepare(&format!("SELECT {} FROM local_tracks WHERE file_path = ? AND cue_file_path IS NULL", Self::TRACK_COLUMNS))
.prepare(&format!(
"SELECT {} FROM local_tracks WHERE file_path = ? AND cue_file_path IS NULL",
Self::TRACK_COLUMNS
))
.map_err(|e| LibraryError::Database(e.to_string()))?;
stmt.query_row(params![path], |row| Self::row_to_track(row))
@@ -1692,7 +1704,10 @@ impl LibraryDatabase {
"SELECT {} FROM local_tracks \
WHERE (title LIKE ?1 OR artist LIKE ?1 OR album LIKE ?1) \
{} {} {}",
Self::TRACK_COLUMNS, source_filter, network_filter, limit_clause
Self::TRACK_COLUMNS,
source_filter,
network_filter,
limit_clause
);
let mut stmt = self
@@ -1754,8 +1769,7 @@ impl LibraryDatabase {
/// Convert a database row to LocalTrack
/// Column list for SELECT queries (avoids fragile SELECT * with positional indices)
const TRACK_COLUMNS: &'static str =
"id, file_path, title, artist, album, album_artist, \
const TRACK_COLUMNS: &'static str = "id, file_path, title, artist, album, album_artist, \
track_number, disc_number, year, genre, duration_secs, format, \
bit_depth, sample_rate, channels, file_size_bytes, \
cue_file_path, cue_start_secs, cue_end_secs, artwork_path, \
@@ -1764,33 +1778,33 @@ impl LibraryDatabase {
fn row_to_track(row: &rusqlite::Row) -> rusqlite::Result<LocalTrack> {
Ok(LocalTrack {
id: row.get(0)?, // id
file_path: row.get(1)?, // file_path
title: row.get(2)?, // title
artist: row.get(3)?, // artist
album: row.get(4)?, // album
album_artist: row.get(5)?, // album_artist
track_number: row.get(6)?, // track_number
disc_number: row.get(7)?, // disc_number
year: row.get(8)?, // year
genre: row.get(9)?, // genre
duration_secs: row.get(10)?, // duration_secs
id: row.get(0)?, // id
file_path: row.get(1)?, // file_path
title: row.get(2)?, // title
artist: row.get(3)?, // artist
album: row.get(4)?, // album
album_artist: row.get(5)?, // album_artist
track_number: row.get(6)?, // track_number
disc_number: row.get(7)?, // disc_number
year: row.get(8)?, // year
genre: row.get(9)?, // genre
duration_secs: row.get(10)?, // duration_secs
format: Self::parse_format(&row.get::<_, String>(11)?), // format
bit_depth: row.get(12)?, // bit_depth
bit_depth: row.get(12)?, // bit_depth
sample_rate: row.get::<_, f64>(13)?, // sample_rate
channels: row.get(14)?, // channels
file_size_bytes: row.get(15)?, // file_size_bytes
cue_file_path: row.get(16)?, // cue_file_path
cue_start_secs: row.get(17)?, // cue_start_secs
cue_end_secs: row.get(18)?, // cue_end_secs
artwork_path: row.get(19)?, // artwork_path
last_modified: row.get(20)?, // last_modified
indexed_at: row.get(21)?, // indexed_at
channels: row.get(14)?, // channels
file_size_bytes: row.get(15)?, // file_size_bytes
cue_file_path: row.get(16)?, // cue_file_path
cue_start_secs: row.get(17)?, // cue_start_secs
cue_end_secs: row.get(18)?, // cue_end_secs
artwork_path: row.get(19)?, // artwork_path
last_modified: row.get(20)?, // last_modified
indexed_at: row.get(21)?, // indexed_at
album_group_key: row.get::<_, Option<String>>(22)?.unwrap_or_default(), // album_group_key
album_group_title: row.get::<_, Option<String>>(23)?.unwrap_or_default(), // album_group_title
source: row.get(24).ok().flatten(), // source
source: row.get(24).ok().flatten(), // source
qobuz_track_id: row.get(25).ok().flatten(), // qobuz_track_id
catalog_number: row.get(26).ok().flatten(), // catalog_number
catalog_number: row.get(26).ok().flatten(), // catalog_number
})
}
@@ -3652,15 +3666,10 @@ impl LibraryDatabase {
}
/// Get custom album cover path for a single album
pub fn get_custom_album_cover(
&self,
album_id: &str,
) -> Result<Option<String>, LibraryError> {
pub fn get_custom_album_cover(&self, album_id: &str) -> Result<Option<String>, LibraryError> {
let mut stmt = self
.conn
.prepare(
"SELECT custom_image_path FROM custom_album_covers WHERE album_id = ?1",
)
.prepare("SELECT custom_image_path FROM custom_album_covers WHERE album_id = ?1")
.map_err(|e| LibraryError::Database(format!("Failed to prepare query: {}", e)))?;
let result = stmt
@@ -3674,10 +3683,7 @@ impl LibraryDatabase {
}
/// Remove a custom album cover
pub fn remove_custom_album_cover(
&self,
album_id: &str,
) -> Result<(), LibraryError> {
pub fn remove_custom_album_cover(&self, album_id: &str) -> Result<(), LibraryError> {
self.conn
.execute(
"DELETE FROM custom_album_covers WHERE album_id = ?1",
@@ -3971,14 +3977,10 @@ impl LibraryDatabase {
let mut stmt = self
.conn
.prepare("SELECT track_id, format_id, file_path FROM downloaded_purchases")
.map_err(|e| {
LibraryError::Database(format!("Failed to prepare statement: {}", e))
})?;
.map_err(|e| LibraryError::Database(format!("Failed to prepare statement: {}", e)))?;
let rows: Vec<(i64, i64, String)> = stmt
.query_map([], |row| {
Ok((row.get(0)?, row.get(1)?, row.get(2)?))
})
.query_map([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))
.map_err(|e| {
LibraryError::Database(format!("Failed to query downloaded purchases: {}", e))
})?
@@ -3998,7 +4000,10 @@ impl LibraryDatabase {
// Remove stale entries where the file no longer exists
if !stale.is_empty() {
log::info!("Removing {} stale downloaded_purchases entries (files deleted)", stale.len());
log::info!(
"Removing {} stale downloaded_purchases entries (files deleted)",
stale.len()
);
for (track_id, format_id) in &stale {
let _ = self.conn.execute(
"DELETE FROM downloaded_purchases WHERE track_id = ?1 AND format_id = ?2",
@@ -4017,9 +4022,7 @@ impl LibraryDatabase {
let mut stmt = self
.conn
.prepare("SELECT track_id, format_id FROM downloaded_purchases")
.map_err(|e| {
LibraryError::Database(format!("Failed to prepare statement: {}", e))
})?;
.map_err(|e| LibraryError::Database(format!("Failed to prepare statement: {}", e)))?;
let rows = stmt
.query_map([], |row| Ok((row.get::<_, i64>(0)?, row.get::<_, i64>(1)?)))
+13 -16
View File
@@ -28,31 +28,28 @@
//! let db = LibraryDatabase::open(Path::new("library.db")).unwrap();
//! ```
mod errors;
mod models;
mod scanner;
mod thumbnails;
mod metadata;
mod cue_parser;
mod database;
mod errors;
mod metadata;
mod models;
mod scanner;
mod tag_sidecar;
mod thumbnails;
// Re-exports
pub use cue_parser::{cue_to_tracks, CueParser, CueSheet, CueTime, CueTrack};
pub use database::{
AlbumTrackUpdate, LibraryDatabase, LibraryFolder, LibraryStats, LocalContentStatus,
PlaylistFolder, PlaylistSettings, PlaylistStats, TrackMetadataUpdateFull,
};
pub use errors::LibraryError;
pub use metadata::MetadataExtractor;
pub use models::*;
pub use scanner::{LibraryScanner, ScanResult};
pub use thumbnails::{
generate_thumbnail, generate_thumbnail_from_bytes,
get_thumbnail_path, get_thumbnails_dir, thumbnail_exists,
get_or_generate_thumbnail, clear_thumbnails, get_cache_size,
};
pub use metadata::MetadataExtractor;
pub use cue_parser::{CueParser, CueSheet, CueTrack, CueTime, cue_to_tracks};
pub use database::{
LibraryDatabase, LibraryFolder, LibraryStats,
AlbumTrackUpdate, TrackMetadataUpdateFull,
PlaylistFolder, PlaylistSettings, PlaylistStats,
LocalContentStatus,
clear_thumbnails, generate_thumbnail, generate_thumbnail_from_bytes, get_cache_size,
get_or_generate_thumbnail, get_thumbnail_path, get_thumbnails_dir, thumbnail_exists,
};
// Re-export database module for backwards compatibility
+85 -41
View File
@@ -5,8 +5,8 @@ use std::fs;
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
use crate::{AudioFormat, AudioProperties, LibraryError, LocalTrack};
use crate::thumbnails::{generate_thumbnail, generate_thumbnail_from_bytes};
use crate::{AudioFormat, AudioProperties, LibraryError, LocalTrack};
/// Metadata extractor using lofty
pub struct MetadataExtractor;
@@ -108,10 +108,18 @@ impl MetadataExtractor {
// Must contain at least one disc-related token
let has_disc_token = tokens.iter().any(|token| {
*token == "disc" || *token == "disk" || *token == "cd"
|| (token.starts_with("disc") && token[4..].chars().all(|c| c.is_ascii_digit()) && !token[4..].is_empty())
|| (token.starts_with("disk") && token[4..].chars().all(|c| c.is_ascii_digit()) && !token[4..].is_empty())
|| (token.starts_with("cd") && token[2..].chars().all(|c| c.is_ascii_digit()) && !token[2..].is_empty())
*token == "disc"
|| *token == "disk"
|| *token == "cd"
|| (token.starts_with("disc")
&& token[4..].chars().all(|c| c.is_ascii_digit())
&& !token[4..].is_empty())
|| (token.starts_with("disk")
&& token[4..].chars().all(|c| c.is_ascii_digit())
&& !token[4..].is_empty())
|| (token.starts_with("cd")
&& token[2..].chars().all(|c| c.is_ascii_digit())
&& !token[2..].is_empty())
});
if !has_disc_token {
@@ -215,7 +223,10 @@ impl MetadataExtractor {
// Only when leading number is 1-2 digits (disc number) followed by dash+digits
if digit_end <= 2 && rest.starts_with('-') {
let after_dash = &rest[1..];
let track_digits: String = after_dash.chars().take_while(|c| c.is_ascii_digit()).collect();
let track_digits: String = after_dash
.chars()
.take_while(|c| c.is_ascii_digit())
.collect();
if !track_digits.is_empty() {
if let Ok(n) = track_digits.parse::<u32>() {
if n > 0 && n < 10000 {
@@ -280,8 +291,18 @@ impl MetadataExtractor {
if let Some(word) = first_word {
if matches!(
word,
"flac" | "mp3" | "aac" | "alac" | "wav" | "aiff" | "ogg"
| "dsd" | "opus" | "wma" | "ape" | "pcm"
"flac"
| "mp3"
| "aac"
| "alac"
| "wav"
| "aiff"
| "ogg"
| "dsd"
| "opus"
| "wma"
| "ape"
| "pcm"
) {
return true;
}
@@ -380,7 +401,9 @@ impl MetadataExtractor {
.map_err(|e| LibraryError::Metadata(format!("Failed to read file: {}", e)))?;
// Get the primary tag (prefer ID3v2/Vorbis/APE)
let tag = tagged_file.primary_tag().or_else(|| tagged_file.first_tag());
let tag = tagged_file
.primary_tag()
.or_else(|| tagged_file.first_tag());
// Get audio properties
let properties = tagged_file.properties();
@@ -424,10 +447,7 @@ impl MetadataExtractor {
LocalTrack {
id: 0,
file_path: file_path.to_string_lossy().to_string(),
title: tag
.title()
.map(|s| s.to_string())
.unwrap_or(filename),
title: tag.title().map(|s| s.to_string()).unwrap_or(filename),
artist: Self::normalize_field(tag.artist().as_deref())
.or_else(|| fallback_artist.clone())
.unwrap_or_else(|| "Unknown Artist".to_string()),
@@ -435,7 +455,9 @@ impl MetadataExtractor {
album_artist: tag.get_string(&ItemKey::AlbumArtist).map(|s| s.to_string()),
album_group_key,
album_group_title,
track_number: tag.track().map(|t| t as u32)
track_number: tag
.track()
.map(|t| t as u32)
.or_else(|| Self::infer_track_number_from_filename(file_path)),
disc_number: tag
.disk()
@@ -443,7 +465,9 @@ impl MetadataExtractor {
.or(inferred_disc),
year: tag.year().map(|y| y as u32),
genre: tag.genre().map(|s| s.to_string()),
catalog_number: tag.get_string(&ItemKey::CatalogNumber).map(|s| s.to_string()),
catalog_number: tag
.get_string(&ItemKey::CatalogNumber)
.map(|s| s.to_string()),
duration_secs,
format,
bit_depth,
@@ -474,8 +498,7 @@ impl MetadataExtractor {
id: 0,
file_path: file_path.to_string_lossy().to_string(),
title: filename,
artist: fallback_artist
.unwrap_or_else(|| "Unknown Artist".to_string()),
artist: fallback_artist.unwrap_or_else(|| "Unknown Artist".to_string()),
album: album_title,
album_artist: None,
album_group_key,
@@ -546,7 +569,9 @@ impl MetadataExtractor {
/// Extract and save artwork as thumbnail to cache directory
pub fn extract_artwork(file_path: &Path, _cache_dir: &Path) -> Option<String> {
let tagged_file = Probe::open(file_path).ok()?.read().ok()?;
let tag = tagged_file.primary_tag().or_else(|| tagged_file.first_tag())?;
let tag = tagged_file
.primary_tag()
.or_else(|| tagged_file.first_tag())?;
let picture = tag.pictures().first()?;
@@ -645,11 +670,8 @@ impl MetadataExtractor {
}
};
let mut score = Self::artwork_score(
&file_key,
album_key.as_deref(),
folder_key.as_deref(),
);
let mut score =
Self::artwork_score(&file_key, album_key.as_deref(), folder_key.as_deref());
if score == 0 {
score = 5;
}
@@ -692,11 +714,7 @@ impl MetadataExtractor {
matches!(ext, "jpg" | "jpeg" | "png" | "webp" | "gif" | "bmp")
}
fn artwork_score(
file_key: &str,
album_key: Option<&str>,
folder_key: Option<&str>,
) -> i32 {
fn artwork_score(file_key: &str, album_key: Option<&str>, folder_key: Option<&str>) -> i32 {
const EXACT: &[&str] = &["cover", "folder", "front", "album", "artwork", "art"];
let mut score = 0;
@@ -752,9 +770,15 @@ mod tests {
#[test]
fn test_is_encoding_folder() {
// QBZ-generated quality folder names
assert!(MetadataExtractor::is_encoding_folder("FLAC 16-bit - 44.1 kHz"));
assert!(MetadataExtractor::is_encoding_folder("FLAC 24-bit - 96 kHz"));
assert!(MetadataExtractor::is_encoding_folder("FLAC 24-bit - 192 kHz"));
assert!(MetadataExtractor::is_encoding_folder(
"FLAC 16-bit - 44.1 kHz"
));
assert!(MetadataExtractor::is_encoding_folder(
"FLAC 24-bit - 96 kHz"
));
assert!(MetadataExtractor::is_encoding_folder(
"FLAC 24-bit - 192 kHz"
));
assert!(MetadataExtractor::is_encoding_folder("MP3 320 kbps"));
// Common encoding folder names from other tools
@@ -792,7 +816,8 @@ mod tests {
#[test]
fn test_album_root_dir_encoding_folder() {
// artist/album/quality/track.flac -> album/
let path = Path::new("/music/EELS/Beautiful Freak/FLAC 24-bit - 96 kHz/01 - Novocaine.flac");
let path =
Path::new("/music/EELS/Beautiful Freak/FLAC 24-bit - 96 kHz/01 - Novocaine.flac");
let root = MetadataExtractor::album_root_dir(path).unwrap();
assert_eq!(root, Path::new("/music/EELS/Beautiful Freak"));
}
@@ -800,7 +825,9 @@ mod tests {
#[test]
fn test_album_root_dir_encoding_and_disc() {
// artist/album/quality/disc1/track.flac -> album/
let path = Path::new("/music/EELS/Beautiful Freak/FLAC 24-bit - 96 kHz/Disc 1/01 - Novocaine.flac");
let path = Path::new(
"/music/EELS/Beautiful Freak/FLAC 24-bit - 96 kHz/Disc 1/01 - Novocaine.flac",
);
let root = MetadataExtractor::album_root_dir(path).unwrap();
assert_eq!(root, Path::new("/music/EELS/Beautiful Freak"));
}
@@ -809,16 +836,22 @@ mod tests {
fn test_infer_track_number_from_filename() {
// Common patterns: "01 - Title"
assert_eq!(
MetadataExtractor::infer_track_number_from_filename(Path::new("/music/01 - Novocaine.flac")),
MetadataExtractor::infer_track_number_from_filename(Path::new(
"/music/01 - Novocaine.flac"
)),
Some(1)
);
assert_eq!(
MetadataExtractor::infer_track_number_from_filename(Path::new("/music/12 - Beautiful Freak.flac")),
MetadataExtractor::infer_track_number_from_filename(Path::new(
"/music/12 - Beautiful Freak.flac"
)),
Some(12)
);
// "01. Title"
assert_eq!(
MetadataExtractor::infer_track_number_from_filename(Path::new("/music/03. Song Name.flac")),
MetadataExtractor::infer_track_number_from_filename(Path::new(
"/music/03. Song Name.flac"
)),
Some(3)
);
// "01_Title"
@@ -848,7 +881,9 @@ mod tests {
);
// Zero is not a valid track number
assert_eq!(
MetadataExtractor::infer_track_number_from_filename(Path::new("/music/00 - Intro.flac")),
MetadataExtractor::infer_track_number_from_filename(Path::new(
"/music/00 - Intro.flac"
)),
None
);
}
@@ -873,11 +908,17 @@ mod tests {
#[test]
fn test_is_disc_folder_false_album_names() {
// Album names containing disc/cd keywords — NOT disc folders (issue #147)
assert!(!MetadataExtractor::is_disc_folder("100 Popular Classics, Disc 1"));
assert!(!MetadataExtractor::is_disc_folder("100 Popular Classics_ Best Loved Works of the Great Composers, Disc 1"));
assert!(!MetadataExtractor::is_disc_folder(
"100 Popular Classics, Disc 1"
));
assert!(!MetadataExtractor::is_disc_folder(
"100 Popular Classics_ Best Loved Works of the Great Composers, Disc 1"
));
assert!(!MetadataExtractor::is_disc_folder("Relaxation Disc1"));
assert!(!MetadataExtractor::is_disc_folder("Now 75 - CD1"));
assert!(!MetadataExtractor::is_disc_folder("Match of the Day - The Album CD1"));
assert!(!MetadataExtractor::is_disc_folder(
"Match of the Day - The Album CD1"
));
assert!(!MetadataExtractor::is_disc_folder("20 Blues Greats"));
assert!(!MetadataExtractor::is_disc_folder("The Beatles"));
assert!(!MetadataExtractor::is_disc_folder("Abbey Road"));
@@ -888,7 +929,10 @@ mod tests {
// Issue #147: album names containing "Disc N" should NOT be treated as disc folders
let path = Path::new("/music/Various Artists/100 Popular Classics, Disc 1/01 - Track.flac");
let root = MetadataExtractor::album_root_dir(path).unwrap();
assert_eq!(root, Path::new("/music/Various Artists/100 Popular Classics, Disc 1"));
assert_eq!(
root,
Path::new("/music/Various Artists/100 Popular Classics, Disc 1")
);
let path = Path::new("/music/Various Artists/Relaxation Disc1/01 - Track.flac");
let root = MetadataExtractor::album_root_dir(path).unwrap();
+4 -4
View File
@@ -57,7 +57,7 @@ pub struct LocalTrack {
pub duration_secs: u64,
pub format: AudioFormat,
pub bit_depth: Option<u32>,
pub sample_rate: f64, // Changed from u32 to f64 to support fractional rates (44.1kHz = 44100Hz)
pub sample_rate: f64, // Changed from u32 to f64 to support fractional rates (44.1kHz = 44100Hz)
pub channels: u8,
pub file_size_bytes: u64,
@@ -97,7 +97,7 @@ impl Default for LocalTrack {
duration_secs: 0,
format: AudioFormat::Unknown,
bit_depth: None,
sample_rate: 44100.0, // Now f64
sample_rate: 44100.0, // Now f64
channels: 2,
file_size_bytes: 0,
cue_file_path: None,
@@ -138,7 +138,7 @@ pub struct LocalAlbum {
pub total_duration_secs: u64,
pub format: AudioFormat,
pub bit_depth: Option<u32>,
pub sample_rate: f64, // Changed from u32 to f64 for decimal precision
pub sample_rate: f64, // Changed from u32 to f64 for decimal precision
pub directory_path: String,
/// Source of the album: "user" for local files, "qobuz_download" for offline cached
#[serde(default = "default_source")]
@@ -201,7 +201,7 @@ pub struct ScanError {
pub struct AudioProperties {
pub duration_secs: u64,
pub bit_depth: Option<u32>,
pub sample_rate: f64, // Changed from u32 to f64 for decimal precision
pub sample_rate: f64, // Changed from u32 to f64 for decimal precision
pub channels: u8,
}
+16 -3
View File
@@ -73,7 +73,10 @@ pub fn read_album_sidecar(album_dir: &Path) -> Result<Option<AlbumTagSidecar>, L
Ok(Some(sidecar))
}
pub fn write_album_sidecar(album_dir: &Path, sidecar: &AlbumTagSidecar) -> Result<(), LibraryError> {
pub fn write_album_sidecar(
album_dir: &Path,
sidecar: &AlbumTagSidecar,
) -> Result<(), LibraryError> {
fs::create_dir_all(album_dir).map_err(LibraryError::Io)?;
let target = sidecar_path(album_dir);
@@ -96,12 +99,22 @@ pub fn delete_album_sidecar(album_dir: &Path) -> Result<(), LibraryError> {
}
pub fn apply_sidecar_to_track(track: &mut LocalTrack, sidecar: &AlbumTagSidecar) {
if let Some(title) = sidecar.album.album_title.as_ref().and_then(|s| normalize(s)) {
if let Some(title) = sidecar
.album
.album_title
.as_ref()
.and_then(|s| normalize(s))
{
track.album = title.clone();
track.album_group_title = title.clone();
}
if let Some(album_artist) = sidecar.album.album_artist.as_ref().and_then(|s| normalize(s)) {
if let Some(album_artist) = sidecar
.album
.album_artist
.as_ref()
.and_then(|s| normalize(s))
{
track.album_artist = Some(album_artist.clone());
}
+6 -4
View File
@@ -20,8 +20,9 @@ pub fn get_thumbnails_dir() -> Result<PathBuf, LibraryError> {
// Create directory if it doesn't exist
if !thumbnails_dir.exists() {
fs::create_dir_all(&thumbnails_dir)
.map_err(|e| LibraryError::Other(format!("Failed to create thumbnails directory: {}", e)))?;
fs::create_dir_all(&thumbnails_dir).map_err(|e| {
LibraryError::Other(format!("Failed to create thumbnails directory: {}", e))
})?;
}
Ok(thumbnails_dir)
@@ -135,8 +136,9 @@ pub fn clear_thumbnails() -> Result<(), LibraryError> {
if thumbnails_dir.exists() {
fs::remove_dir_all(&thumbnails_dir)
.map_err(|e| LibraryError::Other(format!("Failed to clear thumbnails: {}", e)))?;
fs::create_dir_all(&thumbnails_dir)
.map_err(|e| LibraryError::Other(format!("Failed to recreate thumbnails directory: {}", e)))?;
fs::create_dir_all(&thumbnails_dir).map_err(|e| {
LibraryError::Other(format!("Failed to recreate thumbnails directory: {}", e))
})?;
}
Ok(())