mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 07:28:45 -07:00
feat: Enhance room image handling by introducing default image and updating display logic; add unit tests for image resolution
This commit is contained in:
@@ -65,7 +65,6 @@ public class CommunityBoardController(
|
||||
? new()
|
||||
: await db.Rooms
|
||||
.Where(r => ids.Contains(r.Id))
|
||||
.Select(r => new { r.Id, r.Name, r.ImageName })
|
||||
.ToDictionaryAsync(r => r.Id);
|
||||
// 2020.12 FeaturedRoomGroup deserializer (NMPFCIJPODA.PPGFHEDFBEA)
|
||||
// reads required keys: FeaturedRoomGroupId, Name, Rooms (NOT
|
||||
@@ -76,13 +75,13 @@ public class CommunityBoardController(
|
||||
FeaturedRoomGroupId = 0L,
|
||||
Name = group.Name ?? string.Empty,
|
||||
Rooms = ids.Select(id => rooms.TryGetValue(id, out var r)
|
||||
? new { RoomName = r.Name, RoomId = r.Id, ImageName = r.ImageName ?? string.Empty }
|
||||
: new { RoomName = string.Empty, RoomId = id, ImageName = string.Empty })
|
||||
? new { RoomName = r.Name, RoomId = r.Id, ImageName = RoomService.ResolveDisplayImageName(r) }
|
||||
: new { RoomName = string.Empty, RoomId = id, ImageName = RoomService.DefaultRoomImageName })
|
||||
.ToArray(),
|
||||
// Keep the old key around for any 2020.03 clients hitting prod.
|
||||
FeaturedRooms = ids.Select(id => rooms.TryGetValue(id, out var r)
|
||||
? new { RoomName = r.Name, RoomId = r.Id, ImageName = r.ImageName ?? string.Empty }
|
||||
: new { RoomName = string.Empty, RoomId = id, ImageName = string.Empty })
|
||||
? new { RoomName = r.Name, RoomId = r.Id, ImageName = RoomService.ResolveDisplayImageName(r) }
|
||||
: new { RoomName = string.Empty, RoomId = id, ImageName = RoomService.DefaultRoomImageName })
|
||||
.ToArray(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace DorkNet.Server.Services;
|
||||
/// </summary>
|
||||
public class RoomService(DorkNetDbContext db)
|
||||
{
|
||||
public const string DefaultRoomImageName = "image_RecCenter.png";
|
||||
|
||||
/// <summary>
|
||||
/// Idempotent seed of the well-known Rec Room Original rooms — pulled
|
||||
/// from the AGRoomRuntimeConfig.Locations array we walked in
|
||||
@@ -232,7 +234,6 @@ public class RoomService(DorkNetDbContext db)
|
||||
// image/<blob-name> keys, so do NOT require the mapped blob
|
||||
// filename to exist on local disk before using it. Local disk
|
||||
// is only a fallback for rooms with no blob-name mapping.
|
||||
const string ultimateFallback = "image_RecCenter.png";
|
||||
var imagesDir = Path.Combine(AppContext.BaseDirectory, "data", "images");
|
||||
bool OnDisk(string name) =>
|
||||
!string.IsNullOrEmpty(name) && File.Exists(Path.Combine(imagesDir, name));
|
||||
@@ -248,7 +249,7 @@ public class RoomService(DorkNetDbContext db)
|
||||
else if (OnDisk(r.ImageName))
|
||||
preferred = r.ImageName;
|
||||
else
|
||||
preferred = ultimateFallback;
|
||||
preferred = DefaultRoomImageName;
|
||||
|
||||
if (r.ImageName != preferred)
|
||||
{
|
||||
@@ -1085,7 +1086,7 @@ public class RoomService(DorkNetDbContext db)
|
||||
Description = r.Description,
|
||||
CreatorPlayerId = r.CreatorPlayerId,
|
||||
CreatorAccountId = r.CreatorPlayerId,
|
||||
ImageName = r.ImageName,
|
||||
ImageName = ResolveDisplayImageName(r),
|
||||
State = r.State,
|
||||
Accessibility = r.Accessibility,
|
||||
SupportsLevelVoting = r.SupportsLevelVoting,
|
||||
@@ -1129,6 +1130,16 @@ public class RoomService(DorkNetDbContext db)
|
||||
},
|
||||
};
|
||||
|
||||
public static string ResolveDisplayImageName(RoomEntity r)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(r.ImageName))
|
||||
return r.ImageName;
|
||||
|
||||
return RoomImagesByName.TryGetValue(r.Name, out var imageName) && !string.IsNullOrWhiteSpace(imageName)
|
||||
? imageName
|
||||
: DefaultRoomImageName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Idempotent admin overrides applied AFTER SeedAsync. Keeps the seed
|
||||
/// table itself untouched (so a clean DB build still seeds the
|
||||
|
||||
Reference in New Issue
Block a user