From 30fba90e9fbc85f3f794feb645021d6b85f14301 Mon Sep 17 00:00:00 2001 From: Sebastian Lawe Date: Fri, 17 Feb 2023 17:33:41 -0600 Subject: [PATCH] Add ReloadController.cs allows the discovery and reloading of a specified mod via HTTP API --- Penumbra/Api/ReloadController.cs | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Penumbra/Api/ReloadController.cs diff --git a/Penumbra/Api/ReloadController.cs b/Penumbra/Api/ReloadController.cs new file mode 100644 index 00000000..0f8fe19e --- /dev/null +++ b/Penumbra/Api/ReloadController.cs @@ -0,0 +1,34 @@ +using EmbedIO.Routing; +using EmbedIO; +using EmbedIO.WebApi; +using Penumbra.Api.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.IO; + +namespace Penumbra.Api { + public class ReloadController : WebApiController { + private readonly Penumbra _penumbra; + public ReloadController( Penumbra penumbra ) + => _penumbra = penumbra; + + [Route( HttpVerbs.Post, "/reload" )] + public async Task Reload() { + var data = await HttpContext.GetRequestDataAsync(); + if( !string.IsNullOrEmpty( data.ModPath ) && !string.IsNullOrEmpty( data.ModName ) ) { + if(Directory.Exists( data.ModPath ) ) { + _penumbra.Api.AddMod( data.ModPath ); + } + _penumbra.Api.ReloadMod( data.ModPath, data.ModName ); + } + } + + public class ReloadData { + public string ModPath { get; set; } = string.Empty; + public string ModName { get; set; } = string.Empty; + } + } +}