Upload files to "routes/API"
This commit is contained in:
11
routes/API/Equipment.cs
Normal file
11
routes/API/Equipment.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Stella.Routes.API
|
||||||
|
{
|
||||||
|
public class Equipment
|
||||||
|
{
|
||||||
|
[ServerAPI.GET("/api/equipment/v2/getUnlocked")]
|
||||||
|
public List<object> ReturnGetUnlockedEquipment()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
27
routes/API/GameConfigs.cs
Normal file
27
routes/API/GameConfigs.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using Stella.Models;
|
||||||
|
|
||||||
|
namespace Stella.Routes.API
|
||||||
|
{
|
||||||
|
public class GameConfigs
|
||||||
|
{
|
||||||
|
[ServerAPI.GET("/api/gameconfigs/v1/all")]
|
||||||
|
public List<GameConfig> ReturnGameConfigs()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new GameConfig { Key = "VR.ForceVerification", Value = "1" },
|
||||||
|
new GameConfig { Key = "Door.Creative.Title", Value = "PUZZLE" },
|
||||||
|
new GameConfig { Key = "Door.Creative.Query", Value = "#puzzle" },
|
||||||
|
new GameConfig { Key = "Door.Featured.Title", Value = "FEATURED" },
|
||||||
|
new GameConfig { Key = "Door.Featured.Query", Value = "#featured" },
|
||||||
|
new GameConfig { Key = "Door.Quests.Title", Value = "QUESTS" },
|
||||||
|
new GameConfig { Key = "Door.Quests.Query", Value = "#rro #quest" },
|
||||||
|
new GameConfig { Key = "Door.Shooters.Title", Value = "PVP" },
|
||||||
|
new GameConfig { Key = "Door.Shooters.Query", Value = "#rro #pvp" },
|
||||||
|
new GameConfig { Key = "Door.Sports.Title", Value = "Sports and Rec" },
|
||||||
|
new GameConfig { Key = "Door.Sports.Query", Value = "#rro #sport" },
|
||||||
|
new GameConfig { Key = "splitTestHardOverrides", Value = "" },
|
||||||
|
new GameConfig { Key = "splitTestSoftOverrides", Value = "" }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
142
routes/API/Images.cs
Normal file
142
routes/API/Images.cs
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
using MongoDB.Driver;
|
||||||
|
using SixLabors.ImageSharp;
|
||||||
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||||
|
using SixLabors.ImageSharp.Formats.Png;
|
||||||
|
using SixLabors.ImageSharp.Processing;
|
||||||
|
using Stella.Models;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Stella.Routes.API
|
||||||
|
{
|
||||||
|
public class Images
|
||||||
|
{
|
||||||
|
[ServerAPI.GET("/api/images/v2/named")]
|
||||||
|
public List<object> ReturnGetImagesNamed()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
[ServerAPI.POST("/api/images/v4/uploadsaved")]
|
||||||
|
[ServerAPI.UseAuthorization]
|
||||||
|
public async Task<ImageNameDTO> ReturnUploadSaved(HttpContext ctx, MongoDB.User user)
|
||||||
|
{
|
||||||
|
SavedImageMetaDTO? imgMeta = JsonSerializer.Deserialize<SavedImageMetaDTO>(ctx.Request.Form["imgMeta"]!);
|
||||||
|
string fileName = $"{imgMeta?.savedImageType}-{user.DisplayName!.ToPascalCase()}-{DateTime.UtcNow.Year}.{DateTime.UtcNow.Month}.{DateTime.UtcNow.Day}-{DateTime.UtcNow.Hour}.{DateTime.UtcNow.Minute}.{DateTime.UtcNow.Second}.jpg";
|
||||||
|
IFormFile image = ctx.Request.Form.Files["image"]!;
|
||||||
|
|
||||||
|
if (image == null || image.Length == 0)
|
||||||
|
throw new Exception("No image uploaded, buddy.");
|
||||||
|
if (image.ContentType != "image/jpeg")
|
||||||
|
throw new Exception("Upload images that are only ingame buddy");
|
||||||
|
if (image.FileName != "image.dat")
|
||||||
|
throw new Exception("Upload images that are only ingame buddy");
|
||||||
|
|
||||||
|
|
||||||
|
if (image != null && image.Length > 0)
|
||||||
|
{
|
||||||
|
string savePath = Path.Combine("Data", "Images", fileName);
|
||||||
|
|
||||||
|
using FileStream stream = new(savePath, FileMode.Create);
|
||||||
|
await image.CopyToAsync(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imgMeta.roomId == 0 || imgMeta.roomId == -1)
|
||||||
|
{
|
||||||
|
imgMeta.roomId = user.OtherData.DormRoomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imgMeta?.savedImageType == SavedImageType.ShareCamera)
|
||||||
|
{
|
||||||
|
await Logs.SendWebhookAsync(
|
||||||
|
fileName,
|
||||||
|
user.Username,
|
||||||
|
MongoDB.roomsCollection.Find(u => u.Room.RoomId == user.OtherData.DormRoomId).FirstOrDefault().Room.Name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ImageNameDTO
|
||||||
|
{
|
||||||
|
ImageName = fileName
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[ServerAPI.GET("/img/{imageName}")]
|
||||||
|
public IResult GetImages(HttpContext ctx, string imageName)
|
||||||
|
{
|
||||||
|
string imagePath = Path.Combine("Data", "Images", imageName.EndsWith(".jpg") ? imageName : imageName + ".jpg");
|
||||||
|
|
||||||
|
if (!File.Exists(imagePath))
|
||||||
|
return Results.NotFound();
|
||||||
|
|
||||||
|
byte[] imageBytes = File.ReadAllBytes(imagePath);
|
||||||
|
|
||||||
|
bool Square = false;
|
||||||
|
|
||||||
|
string? cropSquare = ctx.Request.Query["cropSquare"];
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(cropSquare) && (cropSquare == "1" || cropSquare == "true"))
|
||||||
|
{
|
||||||
|
Square = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int width = 512;
|
||||||
|
int height = 0;
|
||||||
|
|
||||||
|
string? H = ctx.Request.Query["height"];
|
||||||
|
string? W = ctx.Request.Query["width"];
|
||||||
|
if (!string.IsNullOrEmpty(W) && W.All(char.IsDigit))
|
||||||
|
{
|
||||||
|
width = int.Parse(W);
|
||||||
|
if (width == 256)
|
||||||
|
{
|
||||||
|
width = 512;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrEmpty(H) && H.All(char.IsDigit))
|
||||||
|
{
|
||||||
|
height = int.Parse(H);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (Image I = Image.Load(imageBytes))
|
||||||
|
{
|
||||||
|
if (Square)
|
||||||
|
{
|
||||||
|
Size NewSize = new()
|
||||||
|
{
|
||||||
|
Width = width,
|
||||||
|
Height = height
|
||||||
|
};
|
||||||
|
int size = Math.Min(I.Width, I.Height);
|
||||||
|
Rectangle CropRectangle = new()
|
||||||
|
{
|
||||||
|
X = (I.Width - size) / 2,
|
||||||
|
Y = (I.Height - size) / 2,
|
||||||
|
Width = size,
|
||||||
|
Height = size
|
||||||
|
};
|
||||||
|
int Resize = Math.Max(width, height);
|
||||||
|
I.Mutate(x => x.Crop(CropRectangle).Resize(Resize, Resize));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Size NewSize = new()
|
||||||
|
{
|
||||||
|
Width = width,
|
||||||
|
Height = height
|
||||||
|
};
|
||||||
|
I.Mutate(x => x.Resize(NewSize));
|
||||||
|
}
|
||||||
|
using MemoryStream ms = new();
|
||||||
|
I.Save(ms, new JpegEncoder());
|
||||||
|
imageBytes = ms.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.Request.Query["sig"] == "p1")
|
||||||
|
{
|
||||||
|
ctx.Response.Headers["Content-Signature"] = "key-id=KEY:RSA:p1.rec.net; data=" + Signatures.Sign(imageBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Results.File(imageBytes, "image/jpg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
routes/API/Messages.cs
Normal file
11
routes/API/Messages.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Stella.Routes.API
|
||||||
|
{
|
||||||
|
public class GetMessages
|
||||||
|
{
|
||||||
|
[ServerAPI.GET("/api/messages/v2/get")]
|
||||||
|
public List<object> MessagesGet()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
routes/API/Objectives.cs
Normal file
26
routes/API/Objectives.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
namespace Stella.Routes.API
|
||||||
|
{
|
||||||
|
public class Objectives
|
||||||
|
{
|
||||||
|
[ServerAPI.GET("/api/objectives/v1/myprogress")]
|
||||||
|
[ServerAPI.UseAuthorization]
|
||||||
|
public dynamic ReturnGetObjectivesProgress()
|
||||||
|
{
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
Objectives = new[]
|
||||||
|
{
|
||||||
|
new { Index = 2, Group = 0, Progress = 0, VisualProgress = 0, IsCompleted = false, IsRewarded = false, HasClaimedReward = false },
|
||||||
|
new { Index = 1, Group = 0, Progress = 0, VisualProgress = 0, IsCompleted = false, IsRewarded = false, HasClaimedReward = false },
|
||||||
|
new { Index = 0, Group = 0, Progress = 0, VisualProgress = 0, IsCompleted = false, IsRewarded = false, HasClaimedReward = false },
|
||||||
|
new { Index = 6, Group = 2, Progress = 0, VisualProgress = 0, IsCompleted = false, IsRewarded = false, HasClaimedReward = false }
|
||||||
|
},
|
||||||
|
ObjectiveGroups = new[]
|
||||||
|
{
|
||||||
|
new { Group = 0, IsCompleted = false, ClearedAt = "2025-11-08T00:00:00Z" },
|
||||||
|
new { Group = 2, IsCompleted = false, ClearedAt = "2025-11-08T00:00:00Z" }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user