Refresh fix, Dungeon Builder v2
This commit is contained in:
@@ -7,10 +7,14 @@ namespace Server.Services.Admin.Pages;
|
||||
public class ApiModel : AdminPageModel
|
||||
{
|
||||
private readonly CraftingHandler _craftingHandler;
|
||||
private readonly DungeonHandler? _dungeonHandler;
|
||||
private readonly LootService? _lootService;
|
||||
|
||||
public ApiModel(CraftingHandler craftingHandler)
|
||||
public ApiModel(CraftingHandler craftingHandler, DungeonHandler? dungeonHandler = null, LootService? lootService = null)
|
||||
{
|
||||
_craftingHandler = craftingHandler;
|
||||
_dungeonHandler = dungeonHandler;
|
||||
_lootService = lootService;
|
||||
}
|
||||
|
||||
public IActionResult OnGet()
|
||||
@@ -21,20 +25,51 @@ public class ApiModel : AdminPageModel
|
||||
public async Task<IActionResult> OnPostRefreshCacheAsync([FromQuery] string? type)
|
||||
{
|
||||
var refreshed = new List<string>();
|
||||
var errors = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
if (type == null || type.Equals("recipes", StringComparison.OrdinalIgnoreCase))
|
||||
// Refresh recipes
|
||||
if (type == null || type.Equals("recipes", StringComparison.OrdinalIgnoreCase) || type.Equals("all", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
await _craftingHandler.RefreshRecipeCacheAsync();
|
||||
refreshed.Add("recipes");
|
||||
}
|
||||
|
||||
// Refresh mobs (animations, sprites, definitions)
|
||||
if (type == null || type.Equals("mobs", StringComparison.OrdinalIgnoreCase) || type.Equals("all", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (_dungeonHandler != null)
|
||||
{
|
||||
await _dungeonHandler.RefreshMobCacheAsync();
|
||||
refreshed.Add("mobs");
|
||||
}
|
||||
else
|
||||
{
|
||||
errors.Add("DungeonHandler not available for mob refresh");
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh loot tables
|
||||
if (type == null || type.Equals("loot", StringComparison.OrdinalIgnoreCase) || type.Equals("all", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (_lootService != null)
|
||||
{
|
||||
await _lootService.RefreshCacheAsync();
|
||||
refreshed.Add("loot");
|
||||
}
|
||||
else
|
||||
{
|
||||
errors.Add("LootService not available for loot refresh");
|
||||
}
|
||||
}
|
||||
|
||||
return new JsonResult(new
|
||||
{
|
||||
success = true,
|
||||
message = "Cache refreshed",
|
||||
refreshed,
|
||||
errors = errors.Count > 0 ? errors : null,
|
||||
timestamp = DateTime.UtcNow
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user