mirror of
https://github.com/CannedNet/CannedNet.git
synced 2026-10-25 23:18:54 -07:00
etc stuff
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
@@ -21,8 +21,6 @@ public class APIController
|
||||
var storefrontService = app.Services.GetRequiredService<StorefrontFillService>();
|
||||
var notificationService = app.Services.GetRequiredService<NotificationService>();
|
||||
|
||||
MapImageEndpoints(app);
|
||||
|
||||
app.MapGet("/api/config/v1/amplitude", () => Results.Ok(new
|
||||
{
|
||||
AmplitudeKey = "a",
|
||||
@@ -616,7 +614,7 @@ public class APIController
|
||||
});
|
||||
app.MapGet("/api/storefronts/v1/p2p/betaEnabled", async (HttpRequest request, AppDbContext db) =>
|
||||
{
|
||||
return "true";
|
||||
return "false";
|
||||
});
|
||||
app.MapGet("/api/announcement/v1/get", async (HttpRequest request, AppDbContext db) =>
|
||||
{
|
||||
@@ -1765,6 +1763,45 @@ public class APIController
|
||||
// TODO: implement
|
||||
return Results.Content("{\"Cheered\":false,\"Favorited\":false}", "application/json");
|
||||
});
|
||||
app.MapPost("/api/images/v4/uploadsaved", async (HttpContext context) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var form = await context.Request.ReadFormAsync();
|
||||
var file = form.Files.FirstOrDefault();
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
return Results.BadRequest(new { error = "No file found in request" });
|
||||
}
|
||||
|
||||
var imageId = Guid.NewGuid().ToString("N");
|
||||
var extension = Path.GetExtension(file.FileName).ToLowerInvariant();
|
||||
|
||||
var validExtensions = new[] { ".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp" };
|
||||
if (string.IsNullOrEmpty(extension) || !validExtensions.Contains(extension))
|
||||
{
|
||||
extension = ".png";
|
||||
}
|
||||
|
||||
var savedFileName = imageId + extension;
|
||||
var filePath = Path.Combine(ImagesDir, savedFileName);
|
||||
|
||||
using (var fileStream = File.Create(filePath))
|
||||
{
|
||||
await file.CopyToAsync(fileStream);
|
||||
}
|
||||
|
||||
return Results.Ok(new
|
||||
{
|
||||
ImageName = savedFileName
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Results.Problem($"Error uploading image: {ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static object[]? TryDeserializeTags(string json)
|
||||
@@ -1836,47 +1873,4 @@ public class APIController
|
||||
}
|
||||
ImagesDir = dir;
|
||||
}
|
||||
|
||||
private void MapImageEndpoints(WebApplication app)
|
||||
{
|
||||
app.MapPost("/api/images/v4/uploadsaved", async (HttpContext context) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var form = await context.Request.ReadFormAsync();
|
||||
var file = form.Files.FirstOrDefault();
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
return Results.BadRequest(new { error = "No file found in request" });
|
||||
}
|
||||
|
||||
var imageId = Guid.NewGuid().ToString("N");
|
||||
var extension = Path.GetExtension(file.FileName).ToLowerInvariant();
|
||||
|
||||
var validExtensions = new[] { ".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp" };
|
||||
if (string.IsNullOrEmpty(extension) || !validExtensions.Contains(extension))
|
||||
{
|
||||
extension = ".png";
|
||||
}
|
||||
|
||||
var savedFileName = imageId + extension;
|
||||
var filePath = Path.Combine(ImagesDir, savedFileName);
|
||||
|
||||
using (var fileStream = File.Create(filePath))
|
||||
{
|
||||
await file.CopyToAsync(fileStream);
|
||||
}
|
||||
|
||||
return Results.Ok(new
|
||||
{
|
||||
ImageName = savedFileName
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Results.Problem($"Error uploading image: {ex.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class AccountsController
|
||||
var result = accounts.Select(a => new Account
|
||||
{
|
||||
AccountId = a.AccountId,
|
||||
ProfileImage = a.ProfileImage ?? "hdqeamlcmatc6qzoi2ybgf0ddijjcf.jpg",
|
||||
ProfileImage = a.ProfileImage ?? "DefaultProfileImage.jpg",
|
||||
IsJunior = a.IsJunior,
|
||||
Platforms = a.Platforms ?? 0,
|
||||
PersonalPronouns = a.PersonalPronouns ?? 0,
|
||||
@@ -103,7 +103,7 @@ public class AccountsController
|
||||
var result = new Account
|
||||
{
|
||||
AccountId = account.AccountId,
|
||||
ProfileImage = account.ProfileImage ?? "hdqeamlcmatc6qzoi2ybgf0ddijjcf.jpg",
|
||||
ProfileImage = account.ProfileImage ?? "DefaultProfileImage.jpg",
|
||||
IsJunior = account.IsJunior,
|
||||
Platforms = account.Platforms ?? 0,
|
||||
PersonalPronouns = account.PersonalPronouns ?? 0,
|
||||
@@ -157,7 +157,7 @@ public class AccountsController
|
||||
var account = new Account
|
||||
{
|
||||
AccountId = accountId,
|
||||
ProfileImage = "hdqeamlcmatc6qzoi2ybgf0ddijjcf.jpg",
|
||||
ProfileImage = "DefaultProfileImage.jpg",
|
||||
IsJunior = false,
|
||||
Platforms = 0,
|
||||
PersonalPronouns = 0,
|
||||
@@ -187,6 +187,7 @@ public class AccountsController
|
||||
var maxRoomId = await db.Rooms.MaxAsync(r => (int?)r.RoomId) ?? 0;
|
||||
var maxId = await db.Rooms.MaxAsync(r => (int?)r.Id) ?? 0;
|
||||
var dormRoomId = maxRoomId + 1;
|
||||
var dormId = maxId + 1;
|
||||
var dormRoom = new Room
|
||||
{
|
||||
Id = maxId + 1,
|
||||
@@ -259,8 +260,6 @@ public class AccountsController
|
||||
|
||||
app.MapPut("/account/me/displayname", async (HttpRequest request, AppDbContext db) =>
|
||||
{
|
||||
// TODO: get what the server should actually respond with, OK fails.
|
||||
|
||||
var authHeader = request.Headers.Authorization.ToString();
|
||||
|
||||
if (string.IsNullOrEmpty(authHeader) || !authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
@@ -88,5 +88,11 @@ public class AuthController
|
||||
key = "8oQ+e+WQaOBPbEcakhqs3dwZZdOmmyDUmJSD9u4AHMY="
|
||||
});
|
||||
});
|
||||
|
||||
app.MapGet("/role/developer/{id}", async (HttpRequest request, AppDbContext db, string id) =>
|
||||
{
|
||||
// TODO: implement
|
||||
return Results.Ok(RecNetResult.Ok());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,11 @@ public class ImageController
|
||||
Directory.CreateDirectory(imagesDir);
|
||||
}
|
||||
|
||||
app.MapGet("/{imageId}", (string imageId, HttpContext context) =>
|
||||
app.MapGet("/{imageId}", (string imageId) =>
|
||||
{
|
||||
if (!Directory.Exists(imagesDir))
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
return Task.CompletedTask;
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
var files = Directory.GetFiles(imagesDir, $"{imageId}.*");
|
||||
@@ -27,8 +26,7 @@ public class ImageController
|
||||
|
||||
if (filePath == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
return Task.CompletedTask;
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
var extension = Path.GetExtension(filePath).ToLowerInvariant();
|
||||
@@ -42,8 +40,8 @@ public class ImageController
|
||||
_ => "application/octet-stream"
|
||||
};
|
||||
|
||||
context.Response.ContentType = contentType;
|
||||
return File.OpenRead(filePath).CopyToAsync(context.Response.Body);
|
||||
var fileStream = File.OpenRead(filePath);
|
||||
return Results.File(fileStream, contentType);
|
||||
});
|
||||
|
||||
app.MapGet("/", (HttpContext context) =>
|
||||
@@ -53,14 +51,12 @@ public class ImageController
|
||||
|
||||
if (string.IsNullOrEmpty(imageId))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
return Task.CompletedTask;
|
||||
return Results.BadRequest();
|
||||
}
|
||||
|
||||
if (!Directory.Exists(imagesDir))
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
return Task.CompletedTask;
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
var files = Directory.GetFiles(imagesDir, $"{imageId}.*");
|
||||
@@ -68,8 +64,7 @@ public class ImageController
|
||||
|
||||
if (filePath == null)
|
||||
{
|
||||
context.Response.StatusCode = 404;
|
||||
return Task.CompletedTask;
|
||||
return Results.NotFound();
|
||||
}
|
||||
|
||||
var extension = Path.GetExtension(filePath).ToLowerInvariant();
|
||||
@@ -83,50 +78,8 @@ public class ImageController
|
||||
_ => "application/octet-stream"
|
||||
};
|
||||
|
||||
context.Response.ContentType = contentType;
|
||||
return File.OpenRead(filePath).CopyToAsync(context.Response.Body);
|
||||
});
|
||||
|
||||
app.MapPost("/api/images/v4/uploadsaved", async (HttpContext context) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var form = await context.Request.ReadFormAsync();
|
||||
var file = form.Files.FirstOrDefault();
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
return Results.BadRequest(new { error = "No file found in request" });
|
||||
}
|
||||
|
||||
var imageId = Guid.NewGuid().ToString("N");
|
||||
var extension = Path.GetExtension(file.FileName).ToLowerInvariant();
|
||||
|
||||
var validExtensions = new[] { ".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp" };
|
||||
if (string.IsNullOrEmpty(extension) || !validExtensions.Contains(extension))
|
||||
{
|
||||
extension = ".png";
|
||||
}
|
||||
|
||||
var savedFileName = imageId + extension;
|
||||
var filePath = Path.Combine(imagesDir, savedFileName);
|
||||
|
||||
using (var fileStream = File.Create(filePath))
|
||||
{
|
||||
await file.CopyToAsync(fileStream);
|
||||
}
|
||||
|
||||
return Results.Ok(new
|
||||
{
|
||||
imageId = imageId,
|
||||
imageUrl = $"/{imageId}{extension}",
|
||||
success = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Results.Problem($"Error uploading image: {ex.Message}");
|
||||
}
|
||||
var fileStream = File.OpenRead(filePath);
|
||||
return Results.File(fileStream, contentType);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -33,19 +33,43 @@ public class MatchmakingController
|
||||
return Results.Content(json, "application/json");
|
||||
}
|
||||
|
||||
var result = new List<Account>
|
||||
// Get the player's active room instance
|
||||
var roomInstance = await db.RoomInstances
|
||||
.Where(r => r.OwnerAccountId == accountId)
|
||||
.OrderByDescending(r => r.Id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
var result = new List<object>
|
||||
{
|
||||
new Account
|
||||
new
|
||||
{
|
||||
AccountId = account.AccountId,
|
||||
ProfileImage = account.ProfileImage ?? "hdqeamlcmatc6qzoi2ybgf0ddijjcf.jpg",
|
||||
IsJunior = account.IsJunior,
|
||||
Platforms = account.Platforms ?? 0,
|
||||
PersonalPronouns = account.PersonalPronouns ?? 0,
|
||||
IdentityFlags = account.IdentityFlags ?? 0,
|
||||
Username = account.Username ?? $"Player{account.AccountId}",
|
||||
DisplayName = account.DisplayName ?? $"Player{account.AccountId}",
|
||||
CreatedAt = account.CreatedAt
|
||||
playerId = account.AccountId,
|
||||
statusVisibility = 0,
|
||||
deviceClass = 0,
|
||||
vrMovementMode = 1,
|
||||
roomInstance = roomInstance != null ? new
|
||||
{
|
||||
roomInstanceId = roomInstance.Id > 0 ? roomInstance.Id : roomInstance.roomInstanceId,
|
||||
roomId = roomInstance.roomId,
|
||||
subRoomId = roomInstance.subRoomId,
|
||||
roomInstanceType = roomInstance.roomInstanceType,
|
||||
location = roomInstance.location,
|
||||
dataBlob = roomInstance.dataBlob,
|
||||
eventId = roomInstance.eventId,
|
||||
clubId = roomInstance.clubId,
|
||||
roomCode = roomInstance.roomCode,
|
||||
photonRegionId = roomInstance.photonRegionId,
|
||||
photonRoomId = roomInstance.photonRoomId,
|
||||
name = roomInstance.name,
|
||||
maxCapacity = roomInstance.maxCapacity,
|
||||
isFull = roomInstance.isFull,
|
||||
isPrivate = roomInstance.isPrivate,
|
||||
isInProgress = roomInstance.isInProgress,
|
||||
EncryptVoiceChat = roomInstance.EncryptVoiceChat
|
||||
} : (object?)null,
|
||||
isOnline = roomInstance != null,
|
||||
appVersion = "",
|
||||
platform = account.Platforms ?? 0
|
||||
}
|
||||
};
|
||||
|
||||
@@ -68,10 +92,24 @@ public class MatchmakingController
|
||||
if (!int.TryParse(accountId.AsSpan(), out var id))
|
||||
return Results.Unauthorized();
|
||||
|
||||
request.EnableBuffering();
|
||||
request.Body.Position = 0;
|
||||
var form = await request.ReadFormAsync();
|
||||
int joinMode = 0;
|
||||
if (int.TryParse(form["JoinMode"].ToString(), out var mode))
|
||||
{
|
||||
joinMode = mode;
|
||||
}
|
||||
request.Body.Position = 0;
|
||||
|
||||
Room? roomData = null;
|
||||
var roomLower = room.ToLower();
|
||||
|
||||
if (int.TryParse(room, out var roomId))
|
||||
if (roomLower == "dormroom")
|
||||
{
|
||||
roomData = await db.Rooms.FirstOrDefaultAsync(r => r.IsDorm && r.CreatorAccountId == id);
|
||||
}
|
||||
else if (int.TryParse(room, out var roomId))
|
||||
{
|
||||
roomData = await db.Rooms.FirstOrDefaultAsync(r => r.RoomId == roomId);
|
||||
}
|
||||
@@ -96,6 +134,8 @@ public class MatchmakingController
|
||||
RoomInstance? instanceToUse;
|
||||
string photonRoomId;
|
||||
|
||||
bool isPrivateInstance = joinMode == 2 || roomData.IsDorm;
|
||||
|
||||
var existingInstance = await db.RoomInstances.FirstOrDefaultAsync(r => r.OwnerAccountId == id && r.roomId == roomData.RoomId);
|
||||
|
||||
if (existingInstance != null)
|
||||
@@ -111,7 +151,7 @@ public class MatchmakingController
|
||||
existingInstance.name = roomData.Name;
|
||||
existingInstance.maxCapacity = maxCapacity;
|
||||
existingInstance.isFull = false;
|
||||
existingInstance.isPrivate = false;
|
||||
existingInstance.isPrivate = isPrivateInstance;
|
||||
instanceToUse = existingInstance;
|
||||
}
|
||||
else
|
||||
@@ -131,15 +171,6 @@ public class MatchmakingController
|
||||
photonRoomId = publicInstance.photonRoomId ?? Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
if (room == "DormRoom")
|
||||
{
|
||||
var playerDorm = await db.Rooms.FirstOrDefaultAsync(r => r.IsDorm && r.CreatorAccountId == id);
|
||||
if (playerDorm != null)
|
||||
{
|
||||
roomData.RoomId = playerDorm.RoomId;
|
||||
}
|
||||
}
|
||||
|
||||
instanceToUse = new RoomInstance
|
||||
{
|
||||
OwnerAccountId = id,
|
||||
@@ -154,7 +185,7 @@ public class MatchmakingController
|
||||
name = roomData.Name,
|
||||
maxCapacity = maxCapacity,
|
||||
isFull = false,
|
||||
isPrivate = roomData.IsDorm || roomData.RoomId == 1,
|
||||
isPrivate = isPrivateInstance,
|
||||
isInProgress = false,
|
||||
EncryptVoiceChat = roomData.EncryptVoiceChat
|
||||
};
|
||||
@@ -187,7 +218,7 @@ public class MatchmakingController
|
||||
name = instanceToUse?.name ?? roomData.Name,
|
||||
maxCapacity = instanceToUse?.maxCapacity ?? maxCapacity,
|
||||
isFull = instanceToUse?.isFull ?? false,
|
||||
isPrivate = (roomData.IsDorm || roomData.RoomId == 1) ? true : (instanceToUse?.isPrivate ?? false),
|
||||
isPrivate = isPrivateInstance,
|
||||
isInProgress = instanceToUse?.isInProgress ?? false,
|
||||
EncryptVoiceChat = instanceToUse?.EncryptVoiceChat ?? roomData.EncryptVoiceChat
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user