mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-21 09:49:34 +00:00
Add checks for resource strings (#930)
* Add checks for resource strings * Don't use resource regex against png files
This commit is contained in:
parent
153bd75e26
commit
58664a2c7e
7 changed files with 53 additions and 10 deletions
|
@ -3,6 +3,7 @@ using Discord;
|
|||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Database;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Files;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
|
||||
|
@ -42,6 +43,13 @@ public class PhotosController : ControllerBase
|
|||
GamePhoto? photo = await this.DeserializeBody<GamePhoto>();
|
||||
if (photo == null) return this.BadRequest();
|
||||
|
||||
string[] photoHashes =
|
||||
{
|
||||
photo.LargeHash, photo.MediumHash, photo.SmallHash, photo.PlanHash,
|
||||
};
|
||||
|
||||
if (photoHashes.Any(hash => !FileHelper.ResourceExists(hash))) return this.BadRequest();
|
||||
|
||||
foreach (PhotoEntity p in this.database.Photos.Where(p => p.CreatorId == token.UserId))
|
||||
{
|
||||
if (p.LargeHash == photo.LargeHash) return this.Ok(); // photo already uploaded
|
||||
|
|
|
@ -49,7 +49,6 @@ public class ResourcesController : ControllerBase
|
|||
return this.NotFound();
|
||||
}
|
||||
|
||||
// TODO: check if this is a valid hash
|
||||
[HttpPost("upload/{hash}/unattributed")]
|
||||
[HttpPost("upload/{hash}")]
|
||||
public async Task<IActionResult> UploadResource(string hash)
|
||||
|
|
|
@ -83,12 +83,9 @@ public class UserController : ControllerBase
|
|||
// ReSharper disable once LoopCanBeConvertedToQuery
|
||||
foreach (string? resource in new[]{update.IconHash, update.YayHash, update.MehHash, update.BooHash, update.PlanetHash,})
|
||||
{
|
||||
if (resource == "0") continue;
|
||||
if (string.IsNullOrWhiteSpace(resource)) continue;
|
||||
|
||||
if (resource != null && !resource.StartsWith('g') && !FileHelper.ResourceExists(resource))
|
||||
{
|
||||
return this.BadRequest();
|
||||
}
|
||||
if (!FileHelper.ResourceExists(resource)) return this.BadRequest();
|
||||
}
|
||||
|
||||
if (update.IconHash != null) user.IconHash = update.IconHash;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue