ImageSerializer & Image dynamic router begone
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.DI;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
|
||||
namespace SPTarkov.Server.Core.Routers.Dynamic;
|
||||
|
||||
[Injectable]
|
||||
public class HttpDynamicRouter(ImageRouter imageRouter, JsonUtil jsonUtil)
|
||||
: DynamicRouter(
|
||||
jsonUtil,
|
||||
[
|
||||
new RouteAction<EmptyRequestData>(".jpg", async (_, _, _, _) => await imageRouter.GetImage()),
|
||||
new RouteAction<EmptyRequestData>(".png", async (_, _, _, _) => await imageRouter.GetImage()),
|
||||
new RouteAction<EmptyRequestData>(".ico", async (_, _, _, _) => await imageRouter.GetImage()),
|
||||
]
|
||||
) { }
|
||||
@@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Http;
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Utils;
|
||||
using SPTarkov.Server.Core.Servers.Http;
|
||||
using SPTarkov.Server.Core.Services.Image;
|
||||
using SPTarkov.Server.Core.Utils;
|
||||
|
||||
@@ -13,31 +14,37 @@ public class ImageRouter(
|
||||
ImageRouterService imageRouterService,
|
||||
HttpFileUtil httpFileUtil,
|
||||
ISptLogger<ImageRouter> logger
|
||||
)
|
||||
) : IHttpListener
|
||||
{
|
||||
public void AddRoute(string key, string valueToAdd)
|
||||
{
|
||||
imageRouterService.AddRoute(key.ToLowerInvariant(), valueToAdd);
|
||||
}
|
||||
|
||||
public async Task SendImage(MongoId sessionId, HttpRequest req, HttpResponse resp, object body)
|
||||
public bool CanHandle(MongoId sessionId, HttpContext context)
|
||||
{
|
||||
var url = fileUtil.StripExtension(context.Request.Path, true);
|
||||
var urlKeyLower = url.ToLowerInvariant();
|
||||
|
||||
if (imageRouterService.ExistsByKey(urlKeyLower))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task Handle(MongoId sessionId, HttpContext context)
|
||||
{
|
||||
// remove file extension
|
||||
var url = fileUtil.StripExtension(req.Path, true);
|
||||
var url = fileUtil.StripExtension(context.Request.Path, true);
|
||||
|
||||
// Send image
|
||||
var urlKeyLower = url.ToLowerInvariant();
|
||||
if (imageRouterService.ExistsByKey(urlKeyLower))
|
||||
{
|
||||
await httpFileUtil.SendFile(resp, imageRouterService.GetByKey(urlKeyLower));
|
||||
await httpFileUtil.SendFile(context.Response, imageRouterService.GetByKey(urlKeyLower));
|
||||
return;
|
||||
}
|
||||
|
||||
logger.Warning($"IMAGE: {url} not found");
|
||||
}
|
||||
|
||||
public ValueTask<string> GetImage()
|
||||
{
|
||||
return new ValueTask<string>("IMAGE");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.DI;
|
||||
using SPTarkov.Server.Core.Models.Common;
|
||||
|
||||
namespace SPTarkov.Server.Core.Routers.Serializers;
|
||||
|
||||
[Injectable]
|
||||
public class ImageSerializer(ImageRouter imageRouter) : ISerializer
|
||||
{
|
||||
public async Task Serialize(MongoId sessionID, HttpRequest req, HttpResponse resp, object? body)
|
||||
{
|
||||
await imageRouter.SendImage(sessionID, req, resp, body);
|
||||
}
|
||||
|
||||
public bool CanHandle(string route)
|
||||
{
|
||||
return route == "IMAGE";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user