Compare commits

..
2 Commits
Author SHA1 Message Date
xrain c448381f23 fix middleware bug 2025-11-03 21:41:35 +08:00
xrain 8d5b667c88 fix 2025-11-02 22:18:25 +08:00
4 changed files with 31 additions and 11 deletions
+1 -1
View File
@@ -7,7 +7,7 @@ namespace SimApi.Communications;
/// </summary> /// </summary>
public class SimApiLoginItem public class SimApiLoginItem
{ {
public string Id { get; set; } = null!; public required string Id { get; set; }
public string[] Type { get; set; } = ["user"]; public string[] Type { get; set; } = ["user"];
public Dictionary<string, string> Meta { get; set; } = []; public Dictionary<string, string> Meta { get; set; } = [];
public object? Extra { get; set; } public object? Extra { get; set; }
+17
View File
@@ -4,13 +4,30 @@ public class SimApiJobOptions
{ {
/// <summary> /// <summary>
/// WebUi地址,设置为null表示不启用 /// WebUi地址,设置为null表示不启用
/// 默认 /jobs
/// </summary> /// </summary>
public string? DashboardUrl { get; set; } = "/jobs"; public string? DashboardUrl { get; set; } = "/jobs";
/// <summary>
/// webui 用户
/// 默认 admin
/// </summary>
public string DashboardAuthUser { get; set; } = "admin"; public string DashboardAuthUser { get; set; } = "admin";
/// <summary>
/// webui 密码
/// 默认 Admin@123!
/// </summary>
public string DashboardAuthPass { get; set; } = "Admin@123!"; public string DashboardAuthPass { get; set; } = "Admin@123!";
/// <summary>
/// 设置为null 使用默认redis配置
/// </summary>
public string? RedisConfiguration { get; set; } public string? RedisConfiguration { get; set; }
/// <summary>
/// 设置为null 使用默认redis配置
/// </summary>
public int? Database { get; set; } = null; public int? Database { get; set; } = null;
public SimApiJobServerConfig[] Servers { get; set; } = [new()]; public SimApiJobServerConfig[] Servers { get; set; } = [new()];
} }
+1 -1
View File
@@ -11,7 +11,7 @@ public class SimApiJobWebAuth(string user, string pass) : IDashboardAuthorizatio
public bool Authorize(DashboardContext context) public bool Authorize(DashboardContext context)
{ {
var httpContext = context.GetHttpContext(); var httpContext = context.GetHttpContext();
var authHeader = httpContext.Request.Headers["Authorization"].FirstOrDefault(); var authHeader = httpContext.Request.Headers.Authorization.FirstOrDefault();
if (authHeader != null && authHeader.StartsWith("Basic ")) if (authHeader != null && authHeader.StartsWith("Basic "))
{ {
var encodedUsernamePassword = authHeader.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)[1].Trim(); var encodedUsernamePassword = authHeader.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)[1].Trim();
+3
View File
@@ -24,6 +24,8 @@ public class SimApiExceptionMiddleware(RequestDelegate next, ILogger<SimApiExcep
try try
{ {
await next(context); await next(context);
if (!context.Response.HasStarted)
{
switch (context.Response.StatusCode) switch (context.Response.StatusCode)
{ {
case 200: case 200:
@@ -36,6 +38,7 @@ public class SimApiExceptionMiddleware(RequestDelegate next, ILogger<SimApiExcep
throw new SimApiException(context.Response.StatusCode); throw new SimApiException(context.Response.StatusCode);
} }
} }
}
catch (SimApiException ex) catch (SimApiException ex)
{ {
response = string.IsNullOrEmpty(ex.Message) response = string.IsNullOrEmpty(ex.Message)