|
5 | 5 | * Downloads files from HF repos, manages a local model cache, |
6 | 6 | * and provides listing/deletion of cached models. |
7 | 7 | * |
8 | | - * Cache dir: <userData>/models/huggingface/<repo-slug>/<filename> |
| 8 | + * Cache dir: <userData>/models/<repo-slug>/<filename> |
9 | 9 | */ |
10 | 10 |
|
11 | 11 | import * as fs from 'fs' |
@@ -33,10 +33,37 @@ export interface HfDownloadProgress { |
33 | 33 | // ─── Paths ────────────────────────────────────────────── |
34 | 34 |
|
35 | 35 | const getHfCacheDir = (): string => { |
36 | | - const dir = path.join(getInstallDir(), 'models', 'huggingface') |
| 36 | + const dir = path.join(getInstallDir(), 'models') |
37 | 37 | if (!fs.existsSync(dir)) { |
38 | 38 | fs.mkdirSync(dir, { recursive: true }) |
39 | 39 | } |
| 40 | + |
| 41 | + // Migrate models from legacy models/huggingface/<slug>/ to models/<slug>/ |
| 42 | + const legacyDir = path.join(dir, 'huggingface') |
| 43 | + if (fs.existsSync(legacyDir)) { |
| 44 | + try { |
| 45 | + const entries = fs.readdirSync(legacyDir, { withFileTypes: true }) |
| 46 | + for (const entry of entries) { |
| 47 | + if (entry.isDirectory()) { |
| 48 | + const src = path.join(legacyDir, entry.name) |
| 49 | + const dest = path.join(dir, entry.name) |
| 50 | + if (!fs.existsSync(dest)) { |
| 51 | + fs.renameSync(src, dest) |
| 52 | + log.info(`[huggingface] Migrated ${entry.name} from legacy cache`) |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + // Remove legacy dir if empty (manifest.json may remain) |
| 57 | + const remaining = fs.readdirSync(legacyDir) |
| 58 | + if (remaining.length === 0) { |
| 59 | + fs.rmdirSync(legacyDir) |
| 60 | + log.info('[huggingface] Removed empty legacy huggingface/ directory') |
| 61 | + } |
| 62 | + } catch (e) { |
| 63 | + log.warn('[huggingface] Failed to migrate legacy cache:', e) |
| 64 | + } |
| 65 | + } |
| 66 | + |
40 | 67 | return dir |
41 | 68 | } |
42 | 69 |
|
|
0 commit comments