mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-04-09 18:29:03 +02:00
Return 404 response on failure to parse file id
This commit is contained in:
parent
f31a992e38
commit
c29756ac6e
@ -156,7 +156,7 @@ namespace VoidCat.Controllers
|
||||
[Route("{id}")]
|
||||
public async Task<IActionResult> GetInfo([FromRoute] string id)
|
||||
{
|
||||
var fid = id.FromBase58Guid();
|
||||
if (!id.TryFromBase58Guid(out var fid)) return StatusCode(404);
|
||||
var uid = HttpContext.GetUserId();
|
||||
var isOwner = uid.HasValue && await _userUploads.Uploader(fid) == uid;
|
||||
|
||||
|
@ -47,6 +47,21 @@ public static class Extensions
|
||||
return new Guid(guidBytes);
|
||||
}
|
||||
|
||||
public static bool TryFromBase58Guid(this string base58, out Guid v)
|
||||
{
|
||||
try
|
||||
{
|
||||
v = base58.FromBase58Guid();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
v = Guid.Empty;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ToBase58(this Guid id)
|
||||
{
|
||||
var enc = new NBitcoin.DataEncoders.Base58Encoder();
|
||||
@ -65,7 +80,7 @@ public static class Extensions
|
||||
{
|
||||
return file.EditSecret == editSecret;
|
||||
}
|
||||
|
||||
|
||||
public static string ToHex(this byte[] data)
|
||||
{
|
||||
return BitConverter.ToString(data).Replace("-", string.Empty).ToLower();
|
||||
|
Loading…
x
Reference in New Issue
Block a user