[feat] add ModelManager with caching, manifest management, and Hugging Face API integration

This commit is contained in:
2025-08-27 20:56:05 +02:00
parent da5a76d253
commit 0128bf2eec
8 changed files with 1347 additions and 71 deletions

View File

@@ -792,6 +792,13 @@ fn download_with_progress(dest_path: &Path, entry: &ModelEntry) -> Result<()> {
}
let part_path = dest_path.with_extension("part");
// Guard to cleanup .part on errors
struct TempGuard { path: std::path::PathBuf, armed: bool }
impl TempGuard { fn disarm(&mut self) { self.armed = false; } }
impl Drop for TempGuard {
fn drop(&mut self) { if self.armed { let _ = fs::remove_file(&self.path); } }
}
let mut _tmp_guard = TempGuard { path: part_path.clone(), armed: true };
let mut resume_from: u64 = 0;
if part_path.exists() && ranges_ok {
@@ -893,6 +900,7 @@ fn download_with_progress(dest_path: &Path, entry: &ModelEntry) -> Result<()> {
drop(part_file);
fs::rename(&part_path, dest_path)
.with_context(|| format!("renaming {}{}", part_path.display(), dest_path.display()))?;
_tmp_guard.disarm();
let final_size = fs::metadata(dest_path).map(|m| m.len()).ok();
let elapsed = start.elapsed().as_secs_f64();