I've successfully added support for importing models from multiple URLs with fallback functionality. Users can now paste multiple URLs (one per line) and the system will attempt to download from each URL in sequence if previous attempts fail.
Location: /StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/DirectUrlImportViewModel.cs
Features:
- Accepts multiple URLs (one per line) in a text input field
- Allows users to specify a model filename
- Provides a dropdown to select download location (Models/Checkpoints, Models/VAE, etc.)
- Validates input URLs and provides error messages
- Shows import status during download
- Automatically loads available model folders on initialization
Key Methods:
OnLoaded(): Initializes available download locationsImportCommand(): Validates input and starts the download process usingIModelImportService.DoCustomImport()LoadAvailableDownloadLocations(): Discovers model subdirectories
Location: /StabilityMatrix.Avalonia/Views/DirectUrlImportPage.axaml and DirectUrlImportPage.axaml.cs
UI Elements:
- Title & Description: Explains the feature
- URLs Input Area: Multi-line TextBox for entering download URLs
- Filename Field: Text input for specifying the model filename
- Download Location Dropdown: Select where to save the model
- Status Indicator: Shows current operation status
- Start Download Button: Triggers the import process
- Help Section: Tips for users about fallback URLs and file extensions
Location: /StabilityMatrix.Avalonia/ViewModels/CheckpointBrowserViewModel.cs
Changes:
- Added
DirectUrlImportViewModelparameter to constructor - Added the new view model to the
Pageslist so it appears as a new tab in the Model Browser
Before:
[civitAiBrowserViewModel, huggingFaceViewModel, openModelDbBrowserViewModel]After:
[civitAiBrowserViewModel, huggingFaceViewModel, openModelDbBrowserViewModel, directUrlImportViewModel]Location: /StabilityMatrix.Avalonia/Services/ModelImportService.cs
Changes:
- Modified
DoCustomImport()method to support multiple URLs as fallback options - First URL is used as primary, remaining URLs are stored as fallbacks
- When download fails, the system will automatically try the next URL in the sequence
Implementation:
var uriList = modelUris.ToList();
var primaryUri = uriList.First();
var fallbackUris = uriList.Skip(1).ToList();
var download = trackedDownloadService.NewDownload(primaryUri, downloadPath);
if (fallbackUris.Count > 0)
{
download.FallbackUris = fallbackUris;
}Location: /StabilityMatrix.Core/Models/TrackedDownload.cs
Changes:
- Added
FallbackUrisproperty to store alternative download URLs - Added
currentUrlIndexfield to track which fallback URL is being used - Added
CurrentDownloadUrlcomputed property that returns the appropriate URL based on retry state - Modified
StartDownloadTask()to useCurrentDownloadUrlinstead ofSourceUrl - Enhanced failure handling to try next fallback URL when download fails
Key Addition:
public List<Uri>? FallbackUris { get; set; }
public Uri CurrentDownloadUrl =>
currentUrlIndex > 0 && FallbackUris is { Count: > 0 } && currentUrlIndex - 1 < FallbackUris.Count
? FallbackUris[currentUrlIndex - 1]
: SourceUrl;- User navigates to the new "Direct URL" tab in the Model Browser
- User enters one or more URLs (each on a new line)
- User specifies the filename for the model (e.g.,
model.safetensors) - User selects the download location from the dropdown
- User clicks "Start Download"
- System validates all inputs and initiates the download
- System creates a
TrackedDownloadwith the first URL - Remaining URLs are stored as
FallbackUris - Download starts with the primary URL
- If download succeeds: File is saved to the specified location
- If download fails:
- System checks for IO errors (retries up to 3 times with same URL)
- After 3 retries, if fallback URLs exist, attempts next URL
- Repeats until all URLs are exhausted or download succeeds
- Success notification shown to user
✅ Multiple URL Support: Users can provide multiple URLs as fallback options ✅ Automatic Failover: System automatically tries next URL if previous fails ✅ Model Folder Selection: Choose where to save the model (by model type) ✅ Filename Customization: Specify any filename with proper extension ✅ Error Messages: Clear feedback on validation and import errors ✅ Status Updates: Real-time status of import operation ✅ Per-line URL Parsing: Robust parsing that handles various URL formats
- Enter single URL and verify download starts
- Enter multiple URLs and verify fallback tries if first fails
- Enter invalid URL and verify error message
- Leave filename empty and verify validation error
- Enter invalid URL format and verify error handling
- Test with 3+ URLs to ensure all fallbacks are tried
- Test network timeout to ensure fallback URL is attempted
- Verify downloaded file is in the correct folder
- Test with different file extensions (.safetensors, .ckpt, .pth, etc.)
Potential improvements for future versions:
- Custom folder selection dialog (currently shows "Not yet implemented")
- Preview image URL input for model metadata
- Hash validation for downloaded files
- URL validation before starting download (pre-check if URLs are accessible)
- Queue multiple imports to run sequentially
- Pause/Resume support for large downloads
- Speed limit options for downloads
Required services (injected via dependency injection):
IModelImportService: Handles the actual import processISettingsManager: Accesses settings like models directory pathsINotificationService: Shows user notificationsITrackedDownloadService: Manages download tracking
- The feature integrates seamlessly with the existing model browser architecture
- Uses the same download infrastructure as CivitAI and other model sources
- Follows the existing MVVM pattern used throughout the application
- All error handling includes user-friendly notifications
- The implementation is extensible for future model source integrations