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:
parent
2d7819c731
commit
e736c28c38
@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers
|
||||
{
|
||||
[Route("Radar/{serverId}")]
|
||||
public class RadarController : BaseController
|
||||
{
|
||||
private readonly IManager _manager;
|
||||
@ -21,8 +22,7 @@ namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Radar/{serverId?}")]
|
||||
public IActionResult Index(string serverId = null)
|
||||
public IActionResult Index(string? serverId = null)
|
||||
{
|
||||
var servers = _manager.GetServers()
|
||||
.Where(server => server.GameName == Server.Game.IW4)
|
||||
@ -42,7 +42,7 @@ namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Radar/{serverId}/Map")]
|
||||
[Route("Map")]
|
||||
public IActionResult Map(string serverId = null)
|
||||
{
|
||||
var server = serverId == null
|
||||
@ -67,7 +67,7 @@ namespace IW4MAdmin.Plugins.LiveRadar.Web.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("Radar/{serverId}/Data")]
|
||||
[Route("Data")]
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Data(string serverId = null)
|
||||
{
|
||||
|
@ -5,6 +5,8 @@ namespace Stats.Dtos
|
||||
{
|
||||
public class ChatSearchQuery : ClientPaginationRequest
|
||||
{
|
||||
private int? _queryClientId;
|
||||
|
||||
/// <summary>
|
||||
/// specifies the partial content of the message to search for
|
||||
/// </summary>
|
||||
@ -18,7 +20,11 @@ namespace Stats.Dtos
|
||||
/// <summary>
|
||||
/// identifier for the client
|
||||
/// </summary>
|
||||
public new int? ClientId { get; set; }
|
||||
public int? QueryClientId
|
||||
{
|
||||
get => _queryClientId ?? ClientId;
|
||||
set => _queryClientId = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// only look for messages sent after this date
|
||||
@ -41,9 +47,9 @@ namespace Stats.Dtos
|
||||
|
||||
public DateTime? SentBeforeDateTime =>
|
||||
SentBefore.Add(string.IsNullOrEmpty(SentBeforeTime) ? TimeSpan.Zero : TimeSpan.Parse(SentBeforeTime));
|
||||
|
||||
|
||||
public bool IsExactMatch { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// indicates if the chat is on the meta page
|
||||
/// </summary>
|
||||
|
@ -60,9 +60,9 @@ namespace Stats.Helpers
|
||||
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)
|
||||
|
@ -5,5 +5,5 @@ namespace WebfrontCore.QueryHelpers.Models;
|
||||
public class ChatResourceRequest : ChatSearchQuery
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ using FluentValidation.AspNetCore;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Razor;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore;
|
||||
@ -25,6 +24,8 @@ using System.Threading.Tasks;
|
||||
using Data.Abstractions;
|
||||
using Data.Helpers;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Scalar.AspNetCore;
|
||||
using WebfrontCore.Controllers.API.Validation;
|
||||
using WebfrontCore.Middleware;
|
||||
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.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddSwaggerGen(options => options.SwaggerDoc("v1", new OpenApiInfo { Title = "IW4MAdmin API", Version = "v1" }));
|
||||
|
||||
// allow CORS
|
||||
services.AddCors(_options =>
|
||||
{
|
||||
@ -149,8 +153,19 @@ namespace WebfrontCore
|
||||
app.UseRouting();
|
||||
app.UseAuthorization();
|
||||
app.UseRateLimiter();
|
||||
app.UseSwagger();
|
||||
|
||||
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?}")
|
||||
.RequireRateLimiting("concurrencyPolicy");
|
||||
});
|
||||
|
@ -46,6 +46,8 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.ConcurrencyLimiter" 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="Scalar.AspNetCore" Version="1.2.9" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.9.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user