mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-05 08:29:40 +00:00
Added plugin architecture (#322)
Build and Release / Read metadata (push) Waiting to run
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 / 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 / Read metadata (push) Waiting to run
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 / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (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,48 @@
|
||||
using System.Text;
|
||||
|
||||
using AIStudio.Settings;
|
||||
|
||||
using Lua;
|
||||
|
||||
namespace AIStudio.Tools.PluginSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Loads Lua modules from a plugin directory.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Any plugin can load Lua modules from its own directory. This class is used to load these modules.
|
||||
/// Loading other modules outside the plugin directory is not allowed.
|
||||
/// </remarks>
|
||||
/// <param name="pluginDirectory">The directory where the plugin is located.</param>
|
||||
public sealed class PluginLoader(string pluginDirectory) : ILuaModuleLoader
|
||||
{
|
||||
private static readonly string PLUGIN_BASE_PATH = Path.Join(SettingsManager.DataDirectory, "plugins");
|
||||
|
||||
#region Implementation of ILuaModuleLoader
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Exists(string moduleName)
|
||||
{
|
||||
// Ensure that the user doesn't try to escape the plugin directory:
|
||||
if (moduleName.Contains("..") || pluginDirectory.Contains(".."))
|
||||
return false;
|
||||
|
||||
// Ensure that the plugin directory is nested in the plugin base path:
|
||||
if (!pluginDirectory.StartsWith(PLUGIN_BASE_PATH, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
var path = Path.Join(pluginDirectory, $"{moduleName}.lua");
|
||||
return File.Exists(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async ValueTask<LuaModule> LoadAsync(string moduleName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var path = Path.Join(pluginDirectory, $"{moduleName}.lua");
|
||||
var code = await File.ReadAllTextAsync(path, Encoding.UTF8, cancellationToken);
|
||||
|
||||
return new(moduleName, code);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user