Skip to content

Commit a845630

Browse files
committed
Merge pull request #1151 from ionite34/fix-format-crashes
Fix model browser file name format causing crashes when data is missing (cherry picked from commit e81c237b228ca539acdadfa1e6753e0aeef3690b)
1 parent 3d2667f commit a845630

File tree

7 files changed

+21
-6
lines changed

7 files changed

+21
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning 2.0](https://semver.org/spec/v2
1818
- Fixed [#1403](https://github.com/LykosAI/StabilityMatrix/issues/1403) - Checkpoint Manager filters not being saved correctly
1919
- Fixed "cannot access local variable 'job' where it is not associated with a value" error when running jobs in AI Toolkit
2020
- Fixed Civitai browser not always returning at least 30 results when possible on initial search
21+
- Fixed model browser crashing when downloading a file with invalid characters in the name
22+
- Fixed model browser crashing when no author exists for a model
2123

2224
## v2.15.0
2325
### Added

StabilityMatrix.Avalonia/Models/Inference/FileNameFormat.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,20 @@ public string GetFileName()
3737
return Prefix
3838
+ string.Join(
3939
"",
40-
Parts.Select(part => part.Match(constant => constant, substitution => substitution.Invoke()))
40+
Parts.Select(part =>
41+
part.Match(
42+
constant => constant,
43+
substitution =>
44+
{
45+
// Filter invalid path chars
46+
var result = substitution.Invoke();
47+
return result is null
48+
? null
49+
: Path.GetInvalidFileNameChars()
50+
.Aggregate(result, (current, c) => current.Replace(c, '_'));
51+
}
52+
)
53+
)
4154
)
4255
+ Postfix;
4356
}

StabilityMatrix.Avalonia/Models/Inference/FileNameFormatProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public partial class FileNameFormatProvider
4747
{ "project_name", () => ProjectName },
4848
{ "date", () => DateTime.Now.ToString("yyyy-MM-dd") },
4949
{ "time", () => DateTime.Now.ToString("HH-mm-ss") },
50-
{ "author", () => CivitModel?.Creator.Username },
50+
{ "author", () => CivitModel?.Creator?.Username },
5151
{ "base_model", () => CivitModelVersion?.BaseModel },
5252
{ "file_name", () => Path.GetFileNameWithoutExtension(CivitFile?.Name) },
5353
{ "file_id", () => CivitFile?.Id.ToString() },

StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CheckpointBrowserCardViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private void ToggleFavorite()
212212
[RelayCommand]
213213
public void SearchAuthor()
214214
{
215-
EventManager.Instance.OnNavigateAndFindCivitAuthorRequested(CivitModel.Creator.Username);
215+
EventManager.Instance.OnNavigateAndFindCivitAuthorRequested(CivitModel.Creator?.Username);
216216
}
217217

218218
private async Task DoImport(

StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CivitAiBrowserViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ private async Task CivitModelQuery(CivitModelsRequest request, bool isInfiniteSc
553553
var doesBaseModelTypeMatch =
554554
SelectedBaseModels.Count == 0
555555
? request.BaseModels == null || request.BaseModels.Length == 0
556-
: SelectedBaseModels.SequenceEqual(request.BaseModels);
556+
: SelectedBaseModels.SequenceEqual(request.BaseModels ?? []);
557557
var doesModelTypeMatch =
558558
SelectedModelType == CivitModelType.All
559559
? request.Types == null || request.Types.Length == 0

StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CivitDetailsPageViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ private async Task ShowImageDialog(ImageSource? image)
651651
private void SearchByAuthor()
652652
{
653653
navigationService.GoBack();
654-
EventManager.Instance.OnNavigateAndFindCivitAuthorRequested(CivitModel.Creator.Username);
654+
EventManager.Instance.OnNavigateAndFindCivitAuthorRequested(CivitModel.Creator?.Username);
655655
}
656656

657657
[RelayCommand]

StabilityMatrix.Core/Models/Api/CivitModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class CivitModel
2727
public CivitMode? Mode { get; set; }
2828

2929
[JsonPropertyName("creator")]
30-
public CivitCreator Creator { get; set; }
30+
public CivitCreator? Creator { get; set; }
3131

3232
[JsonPropertyName("stats")]
3333
public CivitModelStats Stats { get; set; }

0 commit comments

Comments
 (0)