feat(card-master): add ICardMasterPayloadProvider singleton, load blob at startup
This commit is contained in:
@@ -130,6 +130,10 @@ public class Program
|
|||||||
// Restart re-fires once per viewer — documented trade in the design spec.
|
// Restart re-fires once per viewer — documented trade in the design spec.
|
||||||
builder.Services.AddSingleton<IHomeDialogSessionTracker, HomeDialogSessionTracker>();
|
builder.Services.AddSingleton<IHomeDialogSessionTracker, HomeDialogSessionTracker>();
|
||||||
|
|
||||||
|
// Loads the static card-master base64 blob from Data/ once at startup; served by
|
||||||
|
// ImmutableDataController. Singleton because the file is ~1.27 MB.
|
||||||
|
builder.Services.AddSingleton<ICardMasterPayloadProvider, CardMasterPayloadProvider>();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
builder.Services.AddBattleNode(opt =>
|
builder.Services.AddBattleNode(opt =>
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace SVSim.EmulatedEntrypoint.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the static card-master blob from the app's output directory once at startup and
|
||||||
|
/// hands the cached base64 string to <c>ImmutableDataController</c>. Singleton because the
|
||||||
|
/// file is ~1.27 MB and gzip-decoding it on every request would burn CPU for no benefit.
|
||||||
|
/// </summary>
|
||||||
|
public interface ICardMasterPayloadProvider
|
||||||
|
{
|
||||||
|
/// <summary>True when the blob loaded successfully and serving is enabled.</summary>
|
||||||
|
bool IsAvailable { get; }
|
||||||
|
|
||||||
|
/// <summary>The verbatim base64 string ready for <c>data.card_master</c>.</summary>
|
||||||
|
string Base64Blob { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class CardMasterPayloadProvider : ICardMasterPayloadProvider
|
||||||
|
{
|
||||||
|
// Filename is pinned to the captured snapshot's date. When swapping the blob, update
|
||||||
|
// this constant AND the hash in CardMasterConfig in the same change.
|
||||||
|
private const string BlobFileName = "card_master_2026-06-03.txt";
|
||||||
|
|
||||||
|
public bool IsAvailable { get; }
|
||||||
|
public string Base64Blob { get; }
|
||||||
|
|
||||||
|
public CardMasterPayloadProvider(ILogger<CardMasterPayloadProvider> log)
|
||||||
|
{
|
||||||
|
var path = Path.Combine(AppContext.BaseDirectory, "Data", BlobFileName);
|
||||||
|
if (!File.Exists(path))
|
||||||
|
{
|
||||||
|
log.LogWarning("Card-master blob missing at {Path} — /immutable_data/card_master will 503.", path);
|
||||||
|
Base64Blob = "";
|
||||||
|
IsAvailable = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Base64Blob = File.ReadAllText(path).Trim();
|
||||||
|
IsAvailable = Base64Blob.Length > 0;
|
||||||
|
log.LogInformation("Loaded card-master blob ({Bytes} base64 chars).", Base64Blob.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user