Files
SPT-Server-Build/Libraries/SPTarkov.Server.Core/Routers/Serializers/NotifySerializer.cs
T
clodanSPT 1af50bfd34 Application cleanup (#485)
* Changed application to use background services and removed hacky http server startup

* Small improvements and method removals

* Removed Core dependency on Web application SDK

* Fixed wrong imported type

---------

Co-authored-by: Alex <clodanSPT@hotmail.com>
Co-authored-by: Chomp <27521899+chompDev@users.noreply.github.com>
2025-07-18 16:21:24 +01:00

40 lines
1.3 KiB
C#

using Microsoft.AspNetCore.Http;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Controllers;
using SPTarkov.Server.Core.DI;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Utils;
namespace SPTarkov.Server.Core.Routers.Serializers;
[Injectable]
public class NotifySerializer(
NotifierController notifierController,
JsonUtil jsonUtil,
HttpServerHelper httpServerHelper
) : ISerializer
{
public async Task Serialize(MongoId sessionID, HttpRequest req, HttpResponse resp, object? body)
{
var splittedUrl = req.Path.Value.Split("/");
var tmpSessionID = splittedUrl[^1].Split("?last_id")[0];
/*
* Take our array of JSON message objects and cast them to JSON strings, so that they can then
* be sent to client as NEWLINE separated strings... yup.
*/
await notifierController
.NotifyAsync(tmpSessionID)
.ContinueWith(messages =>
messages.Result.Select(message => string.Join("\n", jsonUtil.Serialize(message)))
)
.ContinueWith(text => httpServerHelper.SendTextJson(resp, text));
}
public bool CanHandle(string route)
{
return route.ToUpper() == "NOTIFY";
}
}