mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
HTTP Api formatting.
This commit is contained in:
parent
31c9b22b9b
commit
bfb630d317
1 changed files with 39 additions and 49 deletions
|
|
@ -26,13 +26,11 @@ public class HttpApi : IDisposable
|
||||||
private readonly IPenumbraApi _api;
|
private readonly IPenumbraApi _api;
|
||||||
private WebServer? _server;
|
private WebServer? _server;
|
||||||
|
|
||||||
public HttpApi( IPenumbraApi api )
|
public HttpApi(IPenumbraApi api)
|
||||||
{
|
{
|
||||||
_api = api;
|
_api = api;
|
||||||
if( Penumbra.Config.EnableHttpApi )
|
if (Penumbra.Config.EnableHttpApi)
|
||||||
{
|
|
||||||
CreateWebServer();
|
CreateWebServer();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Enabled
|
public bool Enabled
|
||||||
|
|
@ -42,13 +40,13 @@ public class HttpApi : IDisposable
|
||||||
{
|
{
|
||||||
ShutdownWebServer();
|
ShutdownWebServer();
|
||||||
|
|
||||||
_server = new WebServer( o => o
|
_server = new WebServer(o => o
|
||||||
.WithUrlPrefix( Prefix )
|
.WithUrlPrefix(Prefix)
|
||||||
.WithMode( HttpListenerMode.EmbedIO ) )
|
.WithMode(HttpListenerMode.EmbedIO))
|
||||||
.WithCors( Prefix )
|
.WithCors(Prefix)
|
||||||
.WithWebApi( "/api", m => m.WithController( () => new Controller( _api ) ) );
|
.WithWebApi("/api", m => m.WithController(() => new Controller(_api)));
|
||||||
|
|
||||||
_server.StateChanged += ( _, e ) => Penumbra.Log.Information( $"WebServer New State - {e.NewState}" );
|
_server.StateChanged += (_, e) => Penumbra.Log.Information($"WebServer New State - {e.NewState}");
|
||||||
_server.RunAsync();
|
_server.RunAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,88 +63,80 @@ public class HttpApi : IDisposable
|
||||||
{
|
{
|
||||||
private readonly IPenumbraApi _api;
|
private readonly IPenumbraApi _api;
|
||||||
|
|
||||||
public Controller( IPenumbraApi api )
|
public Controller(IPenumbraApi api)
|
||||||
=> _api = api;
|
=> _api = api;
|
||||||
|
|
||||||
public partial object? GetMods()
|
public partial object? GetMods()
|
||||||
{
|
{
|
||||||
Penumbra.Log.Debug( $"[HTTP] {nameof( GetMods )} triggered." );
|
Penumbra.Log.Debug($"[HTTP] {nameof(GetMods)} triggered.");
|
||||||
return _api.GetModList();
|
return _api.GetModList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async partial Task Redraw()
|
public async partial Task Redraw()
|
||||||
{
|
{
|
||||||
var data = await HttpContext.GetRequestDataAsync< RedrawData >();
|
var data = await HttpContext.GetRequestDataAsync<RedrawData>();
|
||||||
Penumbra.Log.Debug( $"[HTTP] {nameof( Redraw )} triggered with {data}." );
|
Penumbra.Log.Debug($"[HTTP] {nameof(Redraw)} triggered with {data}.");
|
||||||
if( data.ObjectTableIndex >= 0 )
|
if (data.ObjectTableIndex >= 0)
|
||||||
{
|
_api.RedrawObject(data.ObjectTableIndex, data.Type);
|
||||||
_api.RedrawObject( data.ObjectTableIndex, data.Type );
|
else if (data.Name.Length > 0)
|
||||||
}
|
_api.RedrawObject(data.Name, data.Type);
|
||||||
else if( data.Name.Length > 0 )
|
|
||||||
{
|
|
||||||
_api.RedrawObject( data.Name, data.Type );
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
_api.RedrawAll(data.Type);
|
||||||
_api.RedrawAll( data.Type );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial void RedrawAll()
|
public partial void RedrawAll()
|
||||||
{
|
{
|
||||||
Penumbra.Log.Debug( $"[HTTP] {nameof( RedrawAll )} triggered." );
|
Penumbra.Log.Debug($"[HTTP] {nameof(RedrawAll)} triggered.");
|
||||||
_api.RedrawAll( RedrawType.Redraw );
|
_api.RedrawAll(RedrawType.Redraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async partial Task ReloadMod()
|
public async partial Task ReloadMod()
|
||||||
{
|
{
|
||||||
var data = await HttpContext.GetRequestDataAsync< ModReloadData >();
|
var data = await HttpContext.GetRequestDataAsync<ModReloadData>();
|
||||||
Penumbra.Log.Debug( $"[HTTP] {nameof( ReloadMod )} triggered with {data}." );
|
Penumbra.Log.Debug($"[HTTP] {nameof(ReloadMod)} triggered with {data}.");
|
||||||
// Add the mod if it is not already loaded and if the directory name is given.
|
// Add the mod if it is not already loaded and if the directory name is given.
|
||||||
// AddMod returns Success if the mod is already loaded.
|
// AddMod returns Success if the mod is already loaded.
|
||||||
if( data.Path.Length != 0 )
|
if (data.Path.Length != 0)
|
||||||
{
|
_api.AddMod(data.Path);
|
||||||
_api.AddMod( data.Path );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reload the mod by path or name, which will also remove no-longer existing mods.
|
// Reload the mod by path or name, which will also remove no-longer existing mods.
|
||||||
_api.ReloadMod( data.Path, data.Name );
|
_api.ReloadMod(data.Path, data.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async partial Task UnpackMod()
|
public async partial Task UnpackMod()
|
||||||
{
|
{
|
||||||
var data = await HttpContext.GetRequestDataAsync< ModUnpackData >();
|
var data = await HttpContext.GetRequestDataAsync<ModUnpackData>();
|
||||||
Penumbra.Log.Debug( $"[HTTP] {nameof( UnpackMod )} triggered with {data}." );
|
Penumbra.Log.Debug($"[HTTP] {nameof(UnpackMod)} triggered with {data}.");
|
||||||
// Unpack the mod package if its valid.
|
// Unpack the mod package if its valid.
|
||||||
if( data.Path.Length != 0 )
|
if (data.Path.Length != 0)
|
||||||
{
|
_api.UnpackMod(data.Path);
|
||||||
_api.UnpackMod( data.Path );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async partial Task OpenWindow()
|
public async partial Task OpenWindow()
|
||||||
{
|
{
|
||||||
Penumbra.Log.Debug($"[HTTP] {nameof(OpenWindow)} triggered.");
|
Penumbra.Log.Debug($"[HTTP] {nameof(OpenWindow)} triggered.");
|
||||||
// Open the penumbra window
|
_api.OpenMainWindow(TabType.Mods, string.Empty, string.Empty);
|
||||||
_api.OpenMainWindow(TabType.Mods, "", "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private record ModReloadData( string Path, string Name )
|
private record ModReloadData(string Path, string Name)
|
||||||
{
|
{
|
||||||
public ModReloadData()
|
public ModReloadData()
|
||||||
: this( string.Empty, string.Empty )
|
: this(string.Empty, string.Empty)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
private record ModUnpackData( string Path)
|
|
||||||
|
private record ModUnpackData(string Path)
|
||||||
{
|
{
|
||||||
public ModUnpackData()
|
public ModUnpackData()
|
||||||
: this( string.Empty) { }
|
: this(string.Empty)
|
||||||
|
{ }
|
||||||
}
|
}
|
||||||
|
|
||||||
private record RedrawData( string Name, RedrawType Type, int ObjectTableIndex )
|
private record RedrawData(string Name, RedrawType Type, int ObjectTableIndex)
|
||||||
{
|
{
|
||||||
public RedrawData()
|
public RedrawData()
|
||||||
: this( string.Empty, RedrawType.Redraw, -1 )
|
: this(string.Empty, RedrawType.Redraw, -1)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue