fix: clear thumbnail cache and temp dirs on new session
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -35,3 +35,10 @@ pub async fn extract_thumbnails(
|
||||
.await
|
||||
.map_err(|e| format!("Task failed: {e}"))?
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn cleanup_thumbnails(paths: Vec<String>) -> Result<(), String> {
|
||||
tokio::task::spawn_blocking(move || thumbnail_extractor::cleanup_thumbnail_dirs(&paths))
|
||||
.await
|
||||
.map_err(|e| format!("Task failed: {e}"))?
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ pub fn run() {
|
||||
media_analysis::extract_keyframes,
|
||||
media_analysis::extract_waveform,
|
||||
media_analysis::extract_thumbnails,
|
||||
media_analysis::cleanup_thumbnails,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
@@ -76,6 +76,17 @@ pub fn extract_thumbnails(
|
||||
Ok(sheets)
|
||||
}
|
||||
|
||||
pub fn cleanup_thumbnail_dirs(paths: &[String]) -> Result<(), String> {
|
||||
for path in paths {
|
||||
let dir = std::path::Path::new(path);
|
||||
if dir.is_dir() {
|
||||
std::fs::remove_dir_all(dir)
|
||||
.map_err(|e| format!("Failed to remove thumbnail dir {path}: {e}"))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user