fixes for capabilities
This commit is contained in:
@@ -183,13 +183,9 @@ public class ApiServer : IApiServer
|
|||||||
semaphore.Release();
|
semaphore.Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IEnumerable<string> GetEndpoints()
|
public virtual Dictionary<string, string[]> GetEndpoints()
|
||||||
{
|
{
|
||||||
return handlers.SelectMany(n => n.Attribute.Methods.Select(m => new
|
return handlers.GroupBy(n => n.Attribute.Route).ToDictionary(n => n.Key, n => n.SelectMany(n => n.Attribute.Methods).ToArray());
|
||||||
{
|
|
||||||
n.Attribute.Route,
|
|
||||||
Method = m,
|
|
||||||
})).OrderBy(n => n.Route).ThenBy(n => n.Method).Select(n => $"{n.Method} {n.Route}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void RegisterHandler<T>(T instance) where T : class
|
public virtual void RegisterHandler<T>(T instance) where T : class
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public interface IApiServer
|
|||||||
void RegisterHandler(Delegate handler);
|
void RegisterHandler(Delegate handler);
|
||||||
void RegisterHandler(Delegate handler, bool throwOnError);
|
void RegisterHandler(Delegate handler, bool throwOnError);
|
||||||
void RegisterHandler(Delegate handler, ApiMessageHandlerAttribute attribute, bool throwOnError);
|
void RegisterHandler(Delegate handler, ApiMessageHandlerAttribute attribute, bool throwOnError);
|
||||||
IEnumerable<string> GetEndpoints();
|
Dictionary<string, string[]> GetEndpoints();
|
||||||
void Stop(bool graceful);
|
void Stop(bool graceful);
|
||||||
void Restart(bool graceful);
|
void Restart(bool graceful);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Pilz.Net.Api.Messages;
|
namespace Pilz.Net.Api.Messages;
|
||||||
|
|
||||||
public class ServerCapabilitiesMessage : ApiMessage
|
public class ServerCapabilitiesMessage(Dictionary<string, string[]> endpoints) : ApiMessage
|
||||||
{
|
{
|
||||||
public List<string> Endpoints { get; } = [];
|
public Dictionary<string, string[]> Endpoints { get; } = endpoints;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,11 @@ public class ServerCapabilitiesHandler : IApiHandlerInitializer
|
|||||||
|
|
||||||
public virtual ApiResult GetCapabilities(ApiRequestInfo req)
|
public virtual ApiResult GetCapabilities(ApiRequestInfo req)
|
||||||
{
|
{
|
||||||
var msg = BuildMessage(req);
|
return ApiResult.Ok(BuildMessage(req));
|
||||||
if (server is ServerCapabilitiesMessage message)
|
|
||||||
message.Endpoints.AddRange(server.GetEndpoints());
|
|
||||||
return ApiResult.Ok(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual ApiMessage? BuildMessage(ApiRequestInfo req)
|
protected virtual ApiMessage? BuildMessage(ApiRequestInfo req)
|
||||||
{
|
{
|
||||||
return new ServerCapabilitiesMessage();
|
return new ServerCapabilitiesMessage(server?.GetEndpoints() ?? []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user