mirror of
https://github.com/CannedNet/CannedNet.git
synced 2026-10-25 15:09:23 -07:00
some extra apis and fix internal server error for images
This commit is contained in:
@@ -238,7 +238,29 @@ public class EconController : ControllerBase
|
||||
[HttpGet("api/avatar/v1/defaultbaseavataritems")]
|
||||
public async Task<IResult> DefaultBaseAvatarItems()
|
||||
{
|
||||
var json = System.IO.File.ReadAllText("JSON/defaultAvatarItems.json");
|
||||
return Results.Content(json, "application/json");
|
||||
return Results.Ok(new List<object>());
|
||||
}
|
||||
|
||||
[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;
|
||||
|
||||
static ImageController() {
|
||||
static ImageController()
|
||||
{
|
||||
Signatures.Init();
|
||||
|
||||
using Image<Rgba32> image = new(64, 64);
|
||||
@@ -23,7 +24,9 @@ public class ImageController : ControllerBase
|
||||
}
|
||||
|
||||
[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");
|
||||
Directory.CreateDirectory(imagesDir);
|
||||
string filePath = Path.Combine(imagesDir, imageName);
|
||||
@@ -31,10 +34,12 @@ public class ImageController : ControllerBase
|
||||
byte[] imageBytes;
|
||||
string contentType;
|
||||
|
||||
if (System.IO.File.Exists(filePath)) {
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
imageBytes = await System.IO.File.ReadAllBytesAsync(filePath);
|
||||
string ext = Path.GetExtension(imageName).ToLowerInvariant();
|
||||
contentType = ext switch {
|
||||
contentType = ext switch
|
||||
{
|
||||
".jpg" or ".jpeg" => "image/jpeg",
|
||||
".gif" => "image/gif",
|
||||
".webp" => "image/webp",
|
||||
@@ -42,7 +47,8 @@ public class ImageController : ControllerBase
|
||||
_ => "image/png"
|
||||
};
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
imageBytes = PlaceholderJpeg;
|
||||
contentType = "image/jpeg";
|
||||
}
|
||||
@@ -51,7 +57,8 @@ public class ImageController : ControllerBase
|
||||
string? widthStr = context.Request.Query["width"].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);
|
||||
return Results.File(imageBytes, contentType);
|
||||
}
|
||||
@@ -61,7 +68,8 @@ public class ImageController : ControllerBase
|
||||
int resizeWidth = 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 x = (image.Width - size) / 2;
|
||||
int y = (image.Height - size) / 2;
|
||||
@@ -74,7 +82,8 @@ public class ImageController : ControllerBase
|
||||
if (int.TryParse(heightStr, out int h))
|
||||
resizeHeight = h;
|
||||
|
||||
if (resizeWidth > 0 || resizeHeight > 0) {
|
||||
if (resizeWidth > 0 || resizeHeight > 0)
|
||||
{
|
||||
image.Mutate(x => x.Resize(resizeWidth, resizeHeight));
|
||||
}
|
||||
|
||||
@@ -85,12 +94,14 @@ public class ImageController : ControllerBase
|
||||
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;
|
||||
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user