BundleSerializer

This commit is contained in:
Alex
2025-02-10 19:40:28 +00:00
parent b572f1da18
commit c26169f53a
2 changed files with 38 additions and 4 deletions
+2 -2
View File
@@ -82,9 +82,9 @@ namespace Core.Loaders
return result;
}
public BundleInfo GetBundle(string bundleKey)
public BundleInfo? GetBundle(string bundleKey)
{
return _cloner.Clone(_bundles[bundleKey]);
return _bundles.GetValueOrDefault(bundleKey);
}
public void AddBundles(string modPath)
@@ -1,5 +1,39 @@
namespace Core.Routers.Serializers;
using Core.DI;
using Core.Loaders;
using Core.Models.Utils;
using Core.Utils;
using SptCommon.Annotations;
public class BundleSerializer
namespace Core.Routers.Serializers;
[Injectable]
public class BundleSerializer(
ISptLogger<BundleSerializer> logger,
BundleLoader bundleLoader,
HttpFileUtil httpFileUtil
) : ISerializer
{
public void Serialize(string sessionID, HttpRequest req, HttpResponse resp, object? body)
{
var key = req.Path.Value.Split("/bundle/")[1];
var bundle = bundleLoader.GetBundle(key);
if (bundle == null)
{
return;
}
logger.Info($"[BUNDLE]: {req.Path.Value}");
if (bundle.ModPath == null)
{
logger.Error($"Mod: {key} lacks a modPath property, skipped loading");
return;
}
httpFileUtil.SendFile(resp, $"{bundle.ModPath}/bundles/{bundle.FileName}");
}
public bool CanHandle(string route)
{
return route == "BUNDLE";
}
}