mirror of
https://github.com/SamueleLorefice/ComfySharp
synced 2026-01-15 03:35:48 +00:00
Added edge case handling for non standard types.
This commit is contained in:
@@ -6,6 +6,7 @@ namespace ComfySharp;
|
|||||||
|
|
||||||
[DataContract, JsonSerializable(typeof(ConversionSettings))]
|
[DataContract, JsonSerializable(typeof(ConversionSettings))]
|
||||||
public class ConversionSettings {
|
public class ConversionSettings {
|
||||||
|
[DataMember(IsRequired = true)] public List<string> BlacklistedNodes = new();
|
||||||
[DataMember(IsRequired = true)] public List<string> EnumConvertAsString = new();
|
[DataMember(IsRequired = true)] public List<string> EnumConvertAsString = new();
|
||||||
[DataMember(IsRequired = true)] public List<string> EnumConvertAsBool = new();
|
[DataMember(IsRequired = true)] public List<string> EnumConvertAsBool = new();
|
||||||
static JsonSerializerOptions jsonOpt = new() { WriteIndented = true, IncludeFields = true };
|
static JsonSerializerOptions jsonOpt = new() { WriteIndented = true, IncludeFields = true };
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ public class NodeDBGenerator {
|
|||||||
if (!knownEnums.ContainsKey(type)) {
|
if (!knownEnums.ContainsKey(type)) {
|
||||||
knownEnums.Add(type, values.ToList());
|
knownEnums.Add(type, values.ToList());
|
||||||
Console.WriteLine("Added new known enum: {0}", type);
|
Console.WriteLine("Added new known enum: {0}", type);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
values.ToList().ForEach(value => {
|
values.ToList().ForEach(value => {
|
||||||
if (!knownEnums[type].Contains(value)) {
|
if (!knownEnums[type].Contains(value)) {
|
||||||
knownEnums[type].Add(value);
|
knownEnums[type].Add(value);
|
||||||
@@ -74,8 +73,7 @@ public class NodeDBGenerator {
|
|||||||
if (!knownStringLists.ContainsKey(type)) {
|
if (!knownStringLists.ContainsKey(type)) {
|
||||||
knownStringLists.Add(type, values.ToList());
|
knownStringLists.Add(type, values.ToList());
|
||||||
Console.WriteLine("Added new known stringList: {0}", type);
|
Console.WriteLine("Added new known stringList: {0}", type);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
values.ToList().ForEach(value => {
|
values.ToList().ForEach(value => {
|
||||||
if (!knownStringLists[type].Contains(value)) {
|
if (!knownStringLists[type].Contains(value)) {
|
||||||
knownStringLists[type].Add(value);
|
knownStringLists[type].Add(value);
|
||||||
@@ -113,6 +111,12 @@ public class NodeDBGenerator {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.WriteLine("Scanning node: {0}", node.Name);
|
Console.WriteLine("Scanning node: {0}", node.Name);
|
||||||
#endif
|
#endif
|
||||||
|
// if this node is blacklisted, skip it
|
||||||
|
if (settings.BlacklistedNodes.Contains(node.Name)) {
|
||||||
|
Console.WriteLine("Skipping blacklisted node: {0}", node.Name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// each of this are top level properties of the node
|
// each of this are top level properties of the node
|
||||||
foreach (var property in node.Value.EnumerateObject()) {
|
foreach (var property in node.Value.EnumerateObject()) {
|
||||||
//if this is a list of input properties:
|
//if this is a list of input properties:
|
||||||
@@ -144,50 +148,48 @@ public class NodeDBGenerator {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.WriteLine("Scanning input field: {0}", inputProperty.Name);
|
Console.WriteLine("Scanning input field: {0}", inputProperty.Name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// if element 0 is a string, this is a type
|
// if element 0 is a string, this is a type
|
||||||
if (inputProperty.Value[0].ValueKind == JsonValueKind.String)
|
if (inputProperty.Value[0].ValueKind == JsonValueKind.String) {
|
||||||
AddKnownType(inputProperty.Value[0].ToString());
|
AddKnownType(inputProperty.Value[0].ToString());
|
||||||
// else, if element 0 is an array, this is an enum or a list.
|
return;
|
||||||
else if (inputProperty.Value[0].ValueKind == JsonValueKind.Array) {
|
}
|
||||||
if (inputProperty.Value[0][0].GetArrayLength() >= 0) {
|
|
||||||
|
// if element 0 is an array, this is an enum or a list.
|
||||||
|
if (inputProperty.Value[0].ValueKind == JsonValueKind.Array) {
|
||||||
|
|
||||||
|
var firstElement = inputProperty.Value.EnumerateArray().ToArray()[0];
|
||||||
|
|
||||||
|
if (firstElement.GetArrayLength() > 0) {
|
||||||
//if the elements inside the array are not strings, this is a list of objects and might require special handling
|
//if the elements inside the array are not strings, this is a list of objects and might require special handling
|
||||||
if (inputProperty.Value[0][0].ValueKind != JsonValueKind.String) {
|
if (firstElement[0].ValueKind != JsonValueKind.String) {
|
||||||
Console.WriteLine("Encountered a special case: {0}", inputProperty.Name);
|
Console.WriteLine("Encountered a special case: {0}", inputProperty.Name);
|
||||||
|
Console.WriteLine("First element of array is not a string, but a {0}", firstElement[0].ValueKind);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> enumValues = new(); //holds all the values of the enum, valid for both following cases
|
List<string> enumValues = new(); //holds all the values of the enum, valid for both following cases
|
||||||
inputProperty.Value[0].EnumerateArray().ToList().ForEach(value => enumValues.Add(value.ToString()));
|
firstElement.EnumerateArray().ToList().ForEach(value => enumValues.Add(value.ToString()));
|
||||||
|
|
||||||
// these are all lists of strings and not enums
|
// these are all lists of strings and not enums
|
||||||
if (settings.EnumConvertAsString.Contains(inputProperty.Name)) {
|
if (settings.EnumConvertAsString.Contains(inputProperty.Name)) {
|
||||||
AddKnownStringList(inputProperty.Name, enumValues);
|
AddKnownStringList(inputProperty.Name, enumValues);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
AddKnownEnum(inputProperty.Name, enumValues);
|
AddKnownEnum(inputProperty.Name, enumValues);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//if the array is empty, this is a list of unknown and might require special handling later on, for now, skip it
|
//if the array is empty, this is a list of unknown and might require special handling later on, for now, skip it
|
||||||
return;
|
Console.WriteLine("Encountered a special case: {0}", inputProperty.Name);
|
||||||
|
Console.WriteLine("First element of array is empty");
|
||||||
|
Console.WriteLine("Adding to known types as empty list...");
|
||||||
|
AddKnownStringList(inputProperty.Name, new List<string>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ScanOutputs(JsonProperty output) { }
|
private void ScanOutputs(JsonProperty output) { }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void GenerateNode(JsonElement data) {
|
public void GenerateNode(JsonElement data) {
|
||||||
var node = new ExpandoObject();
|
var node = new ExpandoObject();
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
{
|
{
|
||||||
|
"BlacklistedNodes" : [
|
||||||
|
"CheckpointLoader|pysssss",
|
||||||
|
"LoraLoader|pysssss",
|
||||||
|
"IFRNet VFI",
|
||||||
|
"RIFE VFI"
|
||||||
|
],
|
||||||
"EnumConvertAsString": [
|
"EnumConvertAsString": [
|
||||||
"ckpt_name",
|
"ckpt_name",
|
||||||
"image",
|
"image",
|
||||||
|
|||||||
Reference in New Issue
Block a user