(modelSizeMB: number)
| 61 | |
| 62 | // Check if there's enough space for a model |
| 63 | async canDownloadModel(modelSizeMB: number): Promise<{ canDownload: boolean; reason?: string }> { |
| 64 | const storageInfo = await this.getStorageInfo(); |
| 65 | const modelSizeBytes = modelSizeMB * 1024 * 1024; |
| 66 | |
| 67 | // Check against our self-imposed limit |
| 68 | const maxStorageBytes = this.MAX_STORAGE_GB * 1024 * 1024 * 1024; |
| 69 | if (storageInfo.totalSizeBytes + modelSizeBytes > maxStorageBytes) { |
| 70 | return { |
| 71 | canDownload: false, |
| 72 | reason: `Would exceed storage limit of ${this.MAX_STORAGE_GB}GB. Consider removing unused models.`, |
| 73 | }; |
| 74 | } |
| 75 | |
| 76 | // Check browser quota if available |
| 77 | if (storageInfo.availableSpace && storageInfo.availableSpace < modelSizeBytes * 1.2) { |
| 78 | return { |
| 79 | canDownload: false, |
| 80 | reason: 'Insufficient browser storage space. Try clearing cache or removing other data.', |
| 81 | }; |
| 82 | } |
| 83 | |
| 84 | return { canDownload: true }; |
| 85 | } |
| 86 | |
| 87 | // Mark a model as downloaded and store metadata |
| 88 | markModelDownloaded(model: LocalModel): void { |
no test coverage detected