Fix world editor tile picker to use configured CDN downloads base URL

This commit is contained in:
dingo
2026-02-14 16:21:24 -05:00
parent 6c0d518ca0
commit 01a357563b
2 changed files with 21 additions and 2 deletions
@@ -169,6 +169,7 @@
const sheets = @Html.Raw(sheetsJson);
const objectDefs = @Html.Raw(objectsJson);
const npcDefs = @Html.Raw(npcsJson);
const cdnBaseUrl = '@Model.CdnBaseUrl';
let currentRegion = null;
let currentZoneChunks = [];
@@ -572,7 +573,9 @@
if (!sheet || !sheet.path) return '';
if (sheet.path.startsWith('http://') || sheet.path.startsWith('https://')) return sheet.path;
const trimmed = sheet.path.replace(/^\/+/, '');
return trimmed.startsWith('downloads/') ? `/${trimmed}` : `/downloads/${trimmed}`;
return trimmed.startsWith('downloads/')
? `${cdnBaseUrl.replace(/\/downloads$/i, '')}/${trimmed}`
: `${cdnBaseUrl}/${trimmed}`;
}
function renderSheetPicker() {
@@ -1,6 +1,7 @@
using DataServer.Data;
using DataServer.Data.Entities;
using GameServices;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Text;
@@ -11,11 +12,13 @@ public class IndexModel : AdminPageModel
{
private readonly GameDbContext _db;
private readonly WorldEditDeltaHub _deltaHub;
private readonly IConfiguration _config;
public IndexModel(GameDbContext db, WorldEditDeltaHub deltaHub)
public IndexModel(GameDbContext db, WorldEditDeltaHub deltaHub, IConfiguration config)
{
_db = db;
_deltaHub = deltaHub;
_config = config;
}
public List<WorldRegion> Regions { get; set; } = new();
@@ -28,9 +31,12 @@ public class IndexModel : AdminPageModel
public int SelectedZoneY { get; set; }
public int SelectedChunkX { get; set; }
public int SelectedChunkY { get; set; }
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com/downloads";
public async Task OnGetAsync(int? regionId, int zoneX = 0, int zoneY = 0, int chunkX = 0, int chunkY = 0)
{
CdnBaseUrl = NormalizeCdnBaseUrl(_config["Cdn:BaseUrl"]);
await EnsureDefaultRegionAsync();
Regions = await _db.WorldRegions
@@ -725,4 +731,14 @@ public class IndexModel : AdminPageModel
private static string ChunkKey(int regionId, int zoneX, int zoneY, int chunkX, int chunkY)
=> $"{regionId}:{zoneX}:{zoneY}:{chunkX}:{chunkY}";
private static string NormalizeCdnBaseUrl(string? baseUrl)
{
baseUrl = (baseUrl ?? "https://assets.aeternalisgames.com").Trim().TrimEnd('/');
if (!baseUrl.EndsWith("/downloads", StringComparison.OrdinalIgnoreCase))
{
baseUrl += "/downloads";
}
return baseUrl;
}
}