BundleSerializer
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user