mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-12 23:53:48 +00:00
Added plugin architecture (#322)
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (linux-arm64) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Build app (linux-arm64) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
This commit is contained in:
1 parent
97454c59e9
commit
ee2a73ccd8
35 files changed
+1319
-13
No files matched your search
@@ -0,0 +1,99 @@
|
||||
namespace AIStudio.Tools.PluginSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a plugin is forbidden.
|
||||
/// </summary>
|
||||
public static class ForbiddenPlugins
|
||||
{
|
||||
private const string ID_PATTERN = "ID = \"";
|
||||
private static readonly int ID_PATTERN_LEN = ID_PATTERN.Length;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the given code represents a forbidden plugin.
|
||||
/// </summary>
|
||||
/// <param name="code">The code to check.</param>
|
||||
/// <returns>The result of the check.</returns>
|
||||
public static PluginCheckResult Check(ReadOnlySpan<char> code)
|
||||
{
|
||||
var endIndex = 0;
|
||||
var foundAnyId = false;
|
||||
var id = ReadOnlySpan<char>.Empty;
|
||||
while (true)
|
||||
{
|
||||
// Create a slice of the code starting at the end index.
|
||||
// This way we can search for all IDs in the code:
|
||||
code = code[endIndex..];
|
||||
|
||||
// Read the next ID as a string:
|
||||
if (!TryGetId(code, out id, out endIndex))
|
||||
{
|
||||
// When no ID was found at all, we block this plugin.
|
||||
// When another ID was found previously, we allow this plugin.
|
||||
if(foundAnyId)
|
||||
return new PluginCheckResult(false, null);
|
||||
|
||||
return new PluginCheckResult(true, "No ID was found.");
|
||||
}
|
||||
|
||||
// Try to parse the ID as a GUID:
|
||||
if (!Guid.TryParse(id, out var parsedGuid))
|
||||
{
|
||||
// Again, when no ID was found at all, we block this plugin.
|
||||
if(foundAnyId)
|
||||
return new PluginCheckResult(false, null);
|
||||
|
||||
return new PluginCheckResult(true, "The ID is not a valid GUID.");
|
||||
}
|
||||
|
||||
// Check if the GUID is forbidden:
|
||||
if (FORBIDDEN_PLUGINS.TryGetValue(parsedGuid, out var reason))
|
||||
return new PluginCheckResult(true, reason);
|
||||
|
||||
foundAnyId = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryGetId(ReadOnlySpan<char> code, out ReadOnlySpan<char> id, out int endIndex)
|
||||
{
|
||||
//
|
||||
// Please note: the code variable is a slice of the original code.
|
||||
// That means the indices are relative to the slice, not the original code.
|
||||
//
|
||||
|
||||
id = ReadOnlySpan<char>.Empty;
|
||||
endIndex = 0;
|
||||
|
||||
// Find the next ID:
|
||||
var idStartIndex = code.IndexOf(ID_PATTERN);
|
||||
if (idStartIndex < 0)
|
||||
return false;
|
||||
|
||||
// Find the start index of the value (Guid):
|
||||
var valueStartIndex = idStartIndex + ID_PATTERN_LEN;
|
||||
|
||||
// Find the end index of the value. In order to do that,
|
||||
// we create a slice of the code starting at the value
|
||||
// start index. That means that the end index is relative
|
||||
// to the inner slice, not the original code nor the outer slice.
|
||||
var valueEndIndex = code[valueStartIndex..].IndexOf('"');
|
||||
if (valueEndIndex < 0)
|
||||
return false;
|
||||
|
||||
// From the perspective of the start index is the end index
|
||||
// the length of the value:
|
||||
endIndex = valueStartIndex + valueEndIndex;
|
||||
id = code.Slice(valueStartIndex, valueEndIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The forbidden plugins.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A dictionary that maps the GUID of a plugin to the reason why it is forbidden.
|
||||
/// </remarks>
|
||||
// ReSharper disable once CollectionNeverUpdated.Local
|
||||
private static readonly Dictionary<Guid, string> FORBIDDEN_PLUGINS =
|
||||
[
|
||||
];
|
||||
}
|
||||
Reference in new issue
Block a user