some extra apis and fix internal server error for images

This commit is contained in:
Lapis
2026-06-14 10:33:40 -04:00
parent 31ec3599ea
commit 4f44b23ff7
2 changed files with 46 additions and 13 deletions
@@ -238,7 +238,29 @@ public class EconController : ControllerBase
[HttpGet("api/avatar/v1/defaultbaseavataritems")] [HttpGet("api/avatar/v1/defaultbaseavataritems")]
public async Task<IResult> DefaultBaseAvatarItems() public async Task<IResult> DefaultBaseAvatarItems()
{ {
var json = System.IO.File.ReadAllText("JSON/defaultAvatarItems.json"); return Results.Ok(new List<object>());
return Results.Content(json, "application/json"); }
[Authorize]
[HttpGet("econ/customAvatarItems/v1/owned")]
public async Task<IResult> GetMyOwnedCustomAvatarItems(int skip, int take)
{
return Results.Ok(new
{
Results = Array.Empty<object>(),
TotalResults = 0
});
}
[HttpGet("api/roomcurrencies/v1/currencies")]
public async Task<IResult> GetRoomCurrencies()
{
return Results.Ok(new List<object>());
}
[HttpGet("api/roomconsumables/v1/roomConsumable/room/{roomId}")]
public async Task<IResult> GetRoomConsumablesForRoom(long roomId)
{
return Results.Ok(new List<object>());
} }
} }
@@ -12,7 +12,8 @@ public class ImageController : ControllerBase
{ {
private static readonly byte[] PlaceholderJpeg; private static readonly byte[] PlaceholderJpeg;
static ImageController() { static ImageController()
{
Signatures.Init(); Signatures.Init();
using Image<Rgba32> image = new(64, 64); using Image<Rgba32> image = new(64, 64);
@@ -23,7 +24,9 @@ public class ImageController : ControllerBase
} }
[HttpGet("{imageName}")] [HttpGet("{imageName}")]
public async Task<IResult> GetImage(HttpContext context, string imageName) { public async Task<IResult> GetImage(string imageName)
{
HttpContext context = HttpContext;
string imagesDir = Path.Combine("Images"); string imagesDir = Path.Combine("Images");
Directory.CreateDirectory(imagesDir); Directory.CreateDirectory(imagesDir);
string filePath = Path.Combine(imagesDir, imageName); string filePath = Path.Combine(imagesDir, imageName);
@@ -31,10 +34,12 @@ public class ImageController : ControllerBase
byte[] imageBytes; byte[] imageBytes;
string contentType; string contentType;
if (System.IO.File.Exists(filePath)) { if (System.IO.File.Exists(filePath))
{
imageBytes = await System.IO.File.ReadAllBytesAsync(filePath); imageBytes = await System.IO.File.ReadAllBytesAsync(filePath);
string ext = Path.GetExtension(imageName).ToLowerInvariant(); string ext = Path.GetExtension(imageName).ToLowerInvariant();
contentType = ext switch { contentType = ext switch
{
".jpg" or ".jpeg" => "image/jpeg", ".jpg" or ".jpeg" => "image/jpeg",
".gif" => "image/gif", ".gif" => "image/gif",
".webp" => "image/webp", ".webp" => "image/webp",
@@ -42,7 +47,8 @@ public class ImageController : ControllerBase
_ => "image/png" _ => "image/png"
}; };
} }
else { else
{
imageBytes = PlaceholderJpeg; imageBytes = PlaceholderJpeg;
contentType = "image/jpeg"; contentType = "image/jpeg";
} }
@@ -51,7 +57,8 @@ public class ImageController : ControllerBase
string? widthStr = context.Request.Query["width"].FirstOrDefault(); string? widthStr = context.Request.Query["width"].FirstOrDefault();
string? heightStr = context.Request.Query["height"].FirstOrDefault(); string? heightStr = context.Request.Query["height"].FirstOrDefault();
if (string.IsNullOrEmpty(widthStr) && string.IsNullOrEmpty(heightStr) && string.IsNullOrEmpty(cropSquare)) { if (string.IsNullOrEmpty(widthStr) && string.IsNullOrEmpty(heightStr) && string.IsNullOrEmpty(cropSquare))
{
SignImageResponse(context, ref imageBytes); SignImageResponse(context, ref imageBytes);
return Results.File(imageBytes, contentType); return Results.File(imageBytes, contentType);
} }
@@ -61,7 +68,8 @@ public class ImageController : ControllerBase
int resizeWidth = 0; int resizeWidth = 0;
int resizeHeight = 0; int resizeHeight = 0;
if (!string.IsNullOrEmpty(cropSquare) && cropSquare != "0" && cropSquare != "false") { if (!string.IsNullOrEmpty(cropSquare) && cropSquare != "0" && cropSquare != "false")
{
int size = Math.Min(image.Width, image.Height); int size = Math.Min(image.Width, image.Height);
int x = (image.Width - size) / 2; int x = (image.Width - size) / 2;
int y = (image.Height - size) / 2; int y = (image.Height - size) / 2;
@@ -74,7 +82,8 @@ public class ImageController : ControllerBase
if (int.TryParse(heightStr, out int h)) if (int.TryParse(heightStr, out int h))
resizeHeight = h; resizeHeight = h;
if (resizeWidth > 0 || resizeHeight > 0) { if (resizeWidth > 0 || resizeHeight > 0)
{
image.Mutate(x => x.Resize(resizeWidth, resizeHeight)); image.Mutate(x => x.Resize(resizeWidth, resizeHeight));
} }
@@ -85,12 +94,14 @@ public class ImageController : ControllerBase
return Results.File(imageBytes, "image/jpeg"); return Results.File(imageBytes, "image/jpeg");
} }
private static void SignImageResponse(HttpContext context, ref byte[] imageBytes) { private static void SignImageResponse(HttpContext context, ref byte[] imageBytes)
{
if (context.Request.Query["sig"] != "p1") return; if (context.Request.Query["sig"] != "p1") return;
string? signature = Signatures.Sign(imageBytes); string? signature = Signatures.Sign(imageBytes);
if (signature != null) { if (signature != null)
{
context.Response.Headers["Content-Signature"] = $"key-id=KEY:RSA:p1.rec.net; data={signature}"; context.Response.Headers["Content-Signature"] = $"key-id=KEY:RSA:p1.rec.net; data={signature}";
} }
} }
} }