Fix level republishing not updating resource or rootLevel

This commit is contained in:
Slendy 2023-04-11 20:23:43 -05:00
parent c50e53ad9a
commit 5fbaa5df20
No known key found for this signature in database
GPG key ID: 7288D68361B91428
2 changed files with 24 additions and 30 deletions

View file

@ -227,12 +227,6 @@ public class PhotosController : ControllerBase
if (photoSlot == null || photoSlot.CreatorId != token.UserId) return this.Unauthorized(); if (photoSlot == null || photoSlot.CreatorId != token.UserId) return this.Unauthorized();
} }
HashSet<string> photoResources = new(){photo.LargeHash, photo.SmallHash, photo.MediumHash, photo.PlanHash,};
foreach (string hash in photoResources)
{
FileHelper.DeleteResource(hash);
}
this.database.Photos.Remove(photo); this.database.Photos.Remove(photo);
await this.database.SaveChangesAsync(); await this.database.SaveChangesAsync();
return this.Ok(); return this.Ok();

View file

@ -1,5 +1,6 @@
#nullable enable #nullable enable
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices;
using LBPUnion.ProjectLighthouse.Configuration; using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions; using LBPUnion.ProjectLighthouse.Extensions;
@ -16,6 +17,7 @@ using LBPUnion.ProjectLighthouse.Types.Users;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Configuration;
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots; namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots;
@ -179,41 +181,39 @@ public class PublishController : ControllerBase
if (!slot.Resources.Contains(slot.RootLevel)) if (!slot.Resources.Contains(slot.RootLevel))
slot.Resources = slot.Resources.Append(rootLevel.Hash).ToArray(); slot.Resources = slot.Resources.Append(rootLevel.Hash).ToArray();
string resourceCollection = string.Join(",", slot.Resources); string resourceCollection = string.Join(",", slot.Resources);
// Republish logic SlotEntity? oldSlot = null;
if (slot.SlotId != 0) if (slot.SlotId != 0)
{ {
SlotEntity? oldSlot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slot.SlotId); oldSlot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == slot.SlotId);
if (oldSlot == null) }
{
Logger.Warn("Rejecting level republish, wasn't able to find old slot", LogArea.Publish);
return this.NotFound();
}
// Republish logic
if (oldSlot != null)
{
if (oldSlot.CreatorId != user.UserId) if (oldSlot.CreatorId != user.UserId)
{ {
Logger.Warn("Rejecting level republish, old level not owned by current user", LogArea.Publish); Logger.Warn("Rejecting level republish, old level not owned by current user", LogArea.Publish);
return this.BadRequest(); return this.BadRequest();
} }
// I hate lbp3 // This is a workaround to prevent lbp3 from overwriting the rootLevel of older levels
if (game != null) // For some reason when republishing in lbp3 it automatically converts the level to lbp3
// so it must be handled here. The game query is only sent by lbp3 so it can be safely assumed
// that if it is present, then the level must be be checked for conversion
GameVersion intendedVersion = game != null ? FromAbbreviation(game) : slot.GameVersion;
if (intendedVersion != GameVersion.Unknown && intendedVersion == slot.GameVersion)
{ {
GameVersion intendedVersion = FromAbbreviation(game); oldSlot.GameVersion = slot.GameVersion;
if (intendedVersion != GameVersion.Unknown && intendedVersion != slotVersion) oldSlot.RootLevel = rootLevel.Hash;
{ oldSlot.ResourceCollection = resourceCollection;
// Delete the useless rootLevel that lbp3 just uploaded }
if (slotVersion == GameVersion.LittleBigPlanet3) else
FileHelper.DeleteResource(rootLevel.Hash); {
else Logger.Warn(
// Only change the rootLevel and gameversion if it's not lbp3 $"Slot rootLevel divergence: game={game}, slotVersion={slot.GameVersion}, intendedVersion={intendedVersion}, oldVersion={oldSlot.GameVersion}",
{ LogArea.Publish);
oldSlot.GameVersion = slot.GameVersion;
oldSlot.RootLevel = rootLevel.Hash;
oldSlot.ResourceCollection = resourceCollection;
}
}
} }
oldSlot.Name = slot.Name; oldSlot.Name = slot.Name;