mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 21:47:22 +00:00
Added PowerPoint templates to the Slide Assistant (#1055)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
8c5cfa78b6
commit
6eb23ebbcb
136 files changed
+16535
-522
No files matched your search
@@ -27,52 +27,15 @@ internal static class PluginIconFile
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(pluginPath))
|
||||
{
|
||||
issue = "The icon path cannot be resolved because the configuration plugin directory is unknown.";
|
||||
return false;
|
||||
}
|
||||
|
||||
var relativePath = iconPath
|
||||
.Replace('/', Path.DirectorySeparatorChar)
|
||||
.Replace('\\', Path.DirectorySeparatorChar);
|
||||
|
||||
if (relativePath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries).Any(segment => segment == ".."))
|
||||
{
|
||||
issue = "The icon path must not contain '..' path segments.";
|
||||
return false;
|
||||
}
|
||||
|
||||
string pluginRoot;
|
||||
string resolvedPath;
|
||||
try
|
||||
{
|
||||
pluginRoot = Path.GetFullPath(pluginPath);
|
||||
resolvedPath = Path.GetFullPath(Path.Combine(pluginRoot, relativePath));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
issue = $"The icon path is invalid: {e.Message}";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PathTools.IsInsideDirectory(pluginRoot, resolvedPath))
|
||||
{
|
||||
issue = "The icon path points outside of the configuration plugin directory.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string.Equals(Path.GetExtension(resolvedPath), ".svg", StringComparison.OrdinalIgnoreCase))
|
||||
if (!string.Equals(Path.GetExtension(iconPath), ".svg", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
issue = "The icon file must use the .svg extension.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!File.Exists(resolvedPath))
|
||||
{
|
||||
issue = "The icon file does not exist.";
|
||||
// The same rules as for every other file a plugin ships:
|
||||
if (!PluginFilePath.TryResolveInside(iconPath, pluginPath, out var resolvedPath, out issue))
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@@ -84,12 +47,6 @@ internal static class PluginIconFile
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!LinksStayInsideDirectory(pluginRoot, resolvedPath))
|
||||
{
|
||||
issue = "The icon path contains a link that points outside of the configuration plugin directory.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return SvgIcon.TryCreateDataUrl(File.ReadAllBytes(resolvedPath), out dataUrl, out issue);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -98,20 +55,4 @@ internal static class PluginIconFile
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool LinksStayInsideDirectory(string rootDirectory, string filePath)
|
||||
{
|
||||
var relativePath = Path.GetRelativePath(rootDirectory, filePath);
|
||||
var currentPath = Path.GetFullPath(rootDirectory);
|
||||
foreach (var segment in relativePath.Split([Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar], StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
currentPath = Path.Combine(currentPath, segment);
|
||||
FileSystemInfo pathInfo = Directory.Exists(currentPath) ? new DirectoryInfo(currentPath) : new FileInfo(currentPath);
|
||||
var finalTarget = pathInfo.ResolveLinkTarget(true);
|
||||
if (finalTarget is not null && !PathTools.IsInsideDirectory(rootDirectory, finalTarget.FullName))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user