Skip to content

Commit 053b0e9

Browse files
committed
Add new ComfyUI support for parsing and executing workflows
1 parent 8da535b commit 053b0e9

File tree

66 files changed

+33858
-6874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+33858
-6874
lines changed

AiServer.ServiceInterface/AppData.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,22 @@ T[] LoadModels<T>(string name) where T : IHasId<string>
8686
}
8787
return models.ToArray();
8888
}
89-
89+
90+
public void LoadComfyWorkflow()
91+
{
92+
var objectInfoJson = ReadTextFile("wwwroot/lib/data/object_info.json")!;
93+
var nodeDefs = ComfyMetadata.Instance.LoadObjectInfo(objectInfoJson);
94+
var overrideObjectInfoJson = ReadTextFile("App_Data/overrides/object_info.json");
95+
if (overrideObjectInfoJson != null)
96+
{
97+
var overrideNodeDefs = ComfyMetadata.ParseNodeDefinitions(overrideObjectInfoJson);
98+
foreach (var entry in overrideNodeDefs)
99+
{
100+
nodeDefs[entry.Key] = entry.Value;
101+
}
102+
}
103+
}
104+
90105
public void Reload(IDbConnection db)
91106
{
92107
Prompts = PocoDataSource.Create(LoadModels<Prompt>("prompts.json")
@@ -101,6 +116,7 @@ public void Reload(IDbConnection db)
101116

102117
LoadModelDefaults();
103118
LogWorkerInfo(AiProviders, "API");
119+
LoadComfyWorkflow();
104120
}
105121

106122
public void ResetAiProviders(IDbConnection db)

AiServer.ServiceInterface/AppExtensions.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,30 @@ public static string ComputeSha256(this Stream stream)
136136
return element.GetRawText();
137137
}
138138
}
139+
140+
/// <summary>
141+
/// Validates that a relative path is safe and doesn't traverse outside the intended directory.
142+
/// </summary>
143+
/// <param name="basePath">The base directory path.</param>
144+
/// <param name="relativePath">The relative path to validate.</param>
145+
/// <returns>True if the path is safe, false otherwise.</returns>
146+
public static bool IsPathSafe(this string relativePath, string basePath)
147+
{
148+
try
149+
{
150+
// Normalize paths to handle different directory separators
151+
basePath = Path.GetFullPath(basePath);
152+
153+
// Combine the base path with the relative path
154+
string fullPath = Path.GetFullPath(Path.Combine(basePath, relativePath));
155+
156+
// Check if the resulting path starts with the base path
157+
return fullPath.StartsWith(basePath, StringComparison.OrdinalIgnoreCase);
158+
}
159+
catch (Exception ex) when (ex is ArgumentException or NotSupportedException or PathTooLongException)
160+
{
161+
// Path contains invalid characters or is in an invalid format
162+
return false;
163+
}
164+
}
139165
}

0 commit comments

Comments
 (0)