Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions StabilityMatrix.Core/Models/Api/CivitImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class CivitImage
public int? NsfwLevel { get; set; }

[JsonPropertyName("width")]
public int Width { get; set; }
public int? Width { get; set; }

[JsonPropertyName("height")]
public int Height { get; set; }
public int? Height { get; set; }

[JsonPropertyName("hash")]
public string Hash { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ private WorkflowMetadata CreateMetadata(string name, bool isMultiple)
new OpenArtThumbnail
{
Url = new Uri(thumbnailUrl),
Width = thumbnail!.Width,
Height = thumbnail.Height,
Width = thumbnail!.Width ?? 0,
Height = thumbnail.Height ?? 0,
},
],
},
Expand Down
78 changes: 78 additions & 0 deletions StabilityMatrix.Tests/Core/CivitImageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Text.Json;
using StabilityMatrix.Core.Models.Api;

namespace StabilityMatrix.Tests.Core;

[TestClass]
public class CivitImageTests
{
[TestMethod]
public void TestDeserialize_CivitImageWithNullDimensions_ShouldBeNull()
{
// CivitAI sends null width/height for some images (observed live 2026-11-06, issue #1792)
const string json = """
{
"url": "https://image.civitai.com/example.jpeg",
"nsfwLevel": 8,
"width": null,
"height": null,
"hash": "abc",
"type": "image"
}
""";

var result = JsonSerializer.Deserialize<CivitImage>(json);

Assert.IsNotNull(result);
Assert.IsNull(result.Width);
Assert.IsNull(result.Height);
Assert.AreEqual("https://image.civitai.com/example.jpeg", result.Url);
}

[TestMethod]
public void TestDeserialize_CivitImageWithDimensions_ShouldReadValues()
{
const string json = """
{ "url": "https://image.civitai.com/example.jpeg", "width": 832, "height": 1216 }
""";

var result = JsonSerializer.Deserialize<CivitImage>(json);

Assert.IsNotNull(result);
Assert.AreEqual(832, result.Width);
Assert.AreEqual(1216, result.Height);
}

[TestMethod]
public void TestDeserialize_ModelsResponseWithNullImageDimensions_ShouldKeepAllItems()
{
// One image with null dimensions used to fail the whole page of results
const string json = """
{
"items": [
{
"id": 1,
"name": "First",
"modelVersions": [
{ "id": 10, "name": "v1", "images": [ { "url": "https://a", "width": 512, "height": 512 } ] }
]
},
{
"id": 2,
"name": "Second",
"modelVersions": [
{ "id": 20, "name": "v1", "images": [ { "url": "https://b", "width": null, "height": null } ] }
]
}
],
"metadata": {}
}
""";

var result = JsonSerializer.Deserialize<CivitModelsResponse>(json);

Assert.IsNotNull(result?.Items);
Assert.AreEqual(2, result.Items.Count);
Assert.IsNull(result.Items[1].ModelVersions![0].Images![0].Width);
}
}
Loading