1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-07 21:58:06 -05:00

Add OpenAPI & Scalar UI

This commit is contained in:
Ayymoss 2024-10-15 22:05:19 +01:00
parent 2d7819c731
commit e736c28c38
No known key found for this signature in database
GPG Key ID: 6F64388D52A78E9E
6 changed files with 34 additions and 11 deletions

View File

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http;
namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers
{ {
[Route("Radar/{serverId}")]
public class RadarController : BaseController public class RadarController : BaseController
{ {
private readonly IManager _manager; private readonly IManager _manager;
@ -21,8 +22,7 @@ namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers
} }
[HttpGet] [HttpGet]
[Route("Radar/{serverId?}")] public IActionResult Index(string? serverId = null)
public IActionResult Index(string serverId = null)
{ {
var servers = _manager.GetServers() var servers = _manager.GetServers()
.Where(server => server.GameName == Server.Game.IW4) .Where(server => server.GameName == Server.Game.IW4)
@ -42,7 +42,7 @@ namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers
} }
[HttpGet] [HttpGet]
[Route("Radar/{serverId}/Map")] [Route("Map")]
public IActionResult Map(string serverId = null) public IActionResult Map(string serverId = null)
{ {
var server = serverId == null var server = serverId == null
@ -67,7 +67,7 @@ namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers
} }
[HttpGet] [HttpGet]
[Route("Radar/{serverId}/Data")] [Route("Data")]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Data(string serverId = null) public IActionResult Data(string serverId = null)
{ {

View File

@ -5,6 +5,8 @@ namespace Stats.Dtos
{ {
public class ChatSearchQuery : ClientPaginationRequest public class ChatSearchQuery : ClientPaginationRequest
{ {
private int? _queryClientId;
/// <summary> /// <summary>
/// specifies the partial content of the message to search for /// specifies the partial content of the message to search for
/// </summary> /// </summary>
@ -18,7 +20,11 @@ namespace Stats.Dtos
/// <summary> /// <summary>
/// identifier for the client /// identifier for the client
/// </summary> /// </summary>
public new int? ClientId { get; set; } public int? QueryClientId
{
get => _queryClientId ?? ClientId;
set => _queryClientId = value;
}
/// <summary> /// <summary>
/// only look for messages sent after this date /// only look for messages sent after this date
@ -41,9 +47,9 @@ namespace Stats.Dtos
public DateTime? SentBeforeDateTime => public DateTime? SentBeforeDateTime =>
SentBefore.Add(string.IsNullOrEmpty(SentBeforeTime) ? TimeSpan.Zero : TimeSpan.Parse(SentBeforeTime)); SentBefore.Add(string.IsNullOrEmpty(SentBeforeTime) ? TimeSpan.Zero : TimeSpan.Parse(SentBeforeTime));
public bool IsExactMatch { get; set; } public bool IsExactMatch { get; set; }
/// <summary> /// <summary>
/// indicates if the chat is on the meta page /// indicates if the chat is on the meta page
/// </summary> /// </summary>

View File

@ -60,9 +60,9 @@ namespace Stats.Helpers
iqMessages = iqMessages.Where(message => message.TimeSent >= query.SentAfterDateTime); iqMessages = iqMessages.Where(message => message.TimeSent >= query.SentAfterDateTime);
} }
if (query.ClientId is not null) if (query.QueryClientId is not null)
{ {
iqMessages = iqMessages.Where(message => message.ClientId == query.ClientId.Value); iqMessages = iqMessages.Where(message => message.ClientId == query.QueryClientId.Value);
} }
if (query.ServerId is not null) if (query.ServerId is not null)

View File

@ -5,5 +5,5 @@ namespace WebfrontCore.QueryHelpers.Models;
public class ChatResourceRequest : ChatSearchQuery public class ChatResourceRequest : ChatSearchQuery
{ {
public bool HasData => !string.IsNullOrEmpty(MessageContains) || !string.IsNullOrEmpty(ServerId) || public bool HasData => !string.IsNullOrEmpty(MessageContains) || !string.IsNullOrEmpty(ServerId) ||
ClientId is not null || SentAfterDateTime is not null; QueryClientId is not null || SentAfterDateTime is not null;
} }

View File

@ -4,7 +4,6 @@ using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SharedLibraryCore; using SharedLibraryCore;
@ -25,6 +24,8 @@ using System.Threading.Tasks;
using Data.Abstractions; using Data.Abstractions;
using Data.Helpers; using Data.Helpers;
using Microsoft.AspNetCore.RateLimiting; using Microsoft.AspNetCore.RateLimiting;
using Microsoft.OpenApi.Models;
using Scalar.AspNetCore;
using WebfrontCore.Controllers.API.Validation; using WebfrontCore.Controllers.API.Validation;
using WebfrontCore.Middleware; using WebfrontCore.Middleware;
using WebfrontCore.QueryHelpers; using WebfrontCore.QueryHelpers;
@ -37,6 +38,9 @@ namespace WebfrontCore
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options => options.SwaggerDoc("v1", new OpenApiInfo { Title = "IW4MAdmin API", Version = "v1" }));
// allow CORS // allow CORS
services.AddCors(_options => services.AddCors(_options =>
{ {
@ -149,8 +153,19 @@ namespace WebfrontCore
app.UseRouting(); app.UseRouting();
app.UseAuthorization(); app.UseAuthorization();
app.UseRateLimiter(); app.UseRateLimiter();
app.UseSwagger();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
endpoints.MapSwagger("openapi/{documentName}.json");
endpoints.MapScalarApiReference(options =>
{
options.WithTitle("IW4MAdmin API")
.WithTheme(ScalarTheme.DeepSpace)
.WithDefaultHttpClient(ScalarTarget.Python, ScalarClient.Requests)
.WithModels(false);
});
endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}") endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}")
.RequireRateLimiting("concurrencyPolicy"); .RequireRateLimiting("concurrencyPolicy");
}); });

View File

@ -46,6 +46,8 @@
<PackageReference Include="Microsoft.AspNetCore.ConcurrencyLimiter" Version="8.0.6" /> <PackageReference Include="Microsoft.AspNetCore.ConcurrencyLimiter" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.6" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.6" />
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" /> <PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.9" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.9.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>