Upload files to "routes/API"

This commit is contained in:
2026-07-24 15:43:17 +00:00
parent 646a270645
commit 50a7e49c46
5 changed files with 346 additions and 0 deletions

18
routes/API/QuickPlay.cs Normal file
View File

@@ -0,0 +1,18 @@
using Stella.Models;
namespace Stella.Routes.API
{
public class QuickPlay
{
[ServerAPI.GET("/api/quickPlay/v1/getandclear")]
[ServerAPI.UseAuthorization]
public dynamic ReturnGetAndClear(MongoDB.User user)
{
return new PlayerQuickPlayDTO
{
RoomName = null,
TargetPlayerId = user.AccountId
};
}
}
}

View File

@@ -0,0 +1,17 @@
namespace Stella.Routes.API
{
public class GetRelationships
{
[ServerAPI.GET("/api/relationships/v2/get")]
public List<object> RelationshipsGet()
{
return [];
}
[ServerAPI.POST("/api/relationships/v1/bulkignoreplatformusers")]
public List<object> BulkIgnorePlatformUsers()
{
return [];
}
}
}

204
routes/API/Rooms.cs Normal file
View File

@@ -0,0 +1,204 @@
using System.Linq;
using System.Net;
using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using MongoDB.Bson;
using MongoDB.Bson.IO;
using MongoDB.Driver;
using Stella.Models;
namespace Stella.Routes.API
{
public class Rooms
{
[ServerAPI.GET("/api/rooms/v4/details/{RoomId}")]
public RoomDetailsDTO ReturnGetRoomInfoById(long RoomId)
{
var room = MongoDB.roomsCollection.Find(u => u.Room.RoomId == RoomId).FirstOrDefault();
return new RoomDetailsDTO
{
Room = room.Room,
Scenes = room.Scenes,
CoOwners = room.CoOwners,
InvitedCoOwners = room.InvitedCoOwners,
Moderators = room.Moderators,
InvitedModerators = room.InvitedModerators,
Hosts = room.Hosts,
InvitedHosts = room.InvitedHosts,
CheerCount = room.CheerCount,
FavoriteCount = room.FavoriteCount,
VisitCount = room.VisitCount,
Tags = room.Tags
};
}
[ServerAPI.GET("/api/rooms/v2/baserooms")]
public async Task<List<RoomDTO>> GetBaseRooms(int id)
{
var roomDoc = await MongoDB.roomsCollection
.Find(u => u.Room.RoomId == 29)
.FirstOrDefaultAsync();
return new List<RoomDTO> { roomDoc.Room };
}
[ServerAPI.GET("/api/rooms/v2/{RoomId}")]
public RoomDTO ReturnGetRoomById(long RoomId)
{
var room = MongoDB.roomsCollection.Find(u => u.Room.RoomId == RoomId).FirstOrDefault();
return room.Room;
}
[ServerAPI.GET("/api/rooms/v2/myrooms")]
[ServerAPI.UseAuthorization]
public async Task<List<RoomDTO>> ReturnMyRooms(MongoDB.User user)
{
int userIdInt = (int)user.AccountId;
var myRooms = await MongoDB.roomsCollection.Find(r => (r.Room.CreatorPlayerId == userIdInt || r.CoOwners.Contains(userIdInt)) && !r.Room.IsDormRoom).ToListAsync();
return myRooms.Select(r => r.Room).ToList();
}
[ServerAPI.GET("/api/rooms/v2/hot")]
public async Task<dynamic> GetHotRooms(string? roomScoreType, string? tags)
{
var filter = Builders<MongoDB.RoomDetailsMongoDB>.Filter.Empty;
var rooms = await MongoDB.roomsCollection.Find(filter).Limit(50).ToListAsync();
if (rooms.Count == 0)
{
return new {};
}
var filtered = rooms.Where(r => r != null && r.Room.Accessibility == Accessibility.Public).Select(r => r.Room).ToList();
if (filtered.Count == 0)
{
return new {};
}
return filtered.Select(r => new RoomOrPlaylist
{
RoomOrPlaylistId = r.RoomId,
Name = r.Name,
State = r.State,
SupportsLevelVoting = r.SupportsLevelVoting,
SupportsMobile = r.SupportsMobile,
SupportsScreens = r.SupportsScreens,
SupportsTeleportVR = r.SupportsTeleportVR,
SupportsVRLow = r.SupportsVRLow,
SupportsWalkVR = r.SupportsWalkVR,
Accessibility = r.Accessibility,
AllowsJuniors = r.AllowsJuniors,
CloningAllowed = r.CloningAllowed,
CreatorPlayerId = r.CreatorPlayerId,
CustomRoomWarning = r.CustomRoomWarning,
Description = r.Description,
DisableMicAutoMute = r.DisableMicAutoMute,
ImageName = r.ImageName,
IsAGRoom = r.IsAGRoom,
IsDormRoom = r.IsDormRoom,
RoomWarningMask = r.WarningMask,
Type = RoomOrPlaylistType.Room
});
}
[ServerAPI.GET("/api/rooms/v2/name/{RoomName}")]
[ServerAPI.UseAuthorization]
public dynamic ReturnGetRoomInfoByName(string RoomName, MongoDB.User user)
{
RoomName = RoomName.Replace("+", " ");
MongoDB.RoomDetailsMongoDB room;
if (RoomName.Equals("dormroom", StringComparison.CurrentCultureIgnoreCase))
{
room = MongoDB.roomsCollection.Find(u => u.Room.RoomId == user.OtherData.DormRoomId).FirstOrDefault();
room.Room.Name = "DormRoom";
}
else
{
room = MongoDB.roomsCollection.Find(u => u.Room.Name == RoomName).FirstOrDefault();
}
return room.Room;
}
[ServerAPI.POST("/api/rooms/v1/clone")]
[ServerAPI.UseAuthorization]
public async Task<object> CloneRoom(HttpContext ctx, MongoDB.User user)
{
using var reader = new StreamReader(ctx.Request.Body);
var body = await reader.ReadToEndAsync();
var json1 = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(body);
var roomName = json1?["Name"].GetString();
var original = await MongoDB.roomsCollection.Find(u => u.Room.RoomId == 29).FirstOrDefaultAsync();
var bannedJson = await File.ReadAllTextAsync("Data/bannednames.json");
var bannedObj = JsonSerializer.Deserialize<Dictionary<string, List<string>>>(bannedJson);
var bannedWords = bannedObj?["banned"] ?? new List<string>();
if (!string.IsNullOrWhiteSpace(roomName) && bannedWords.Any(word => roomName.Contains(word, StringComparison.OrdinalIgnoreCase)))
{
return new
{
Result = 1
};
}
if (original == null)
{
throw new Exception("couldnt find maker room");
}
var max = await MongoDB.roomsCollection.Find(_ => true).SortByDescending(r => r.Room.RoomId).FirstOrDefaultAsync();
int newId = (int)((max?.Room.RoomId ?? 29) + 1);
string json = JsonSerializer.Serialize(original);
var newRoomDoc = JsonSerializer.Deserialize<MongoDB.RoomDetailsMongoDB>(json)!;
newRoomDoc.Id = ObjectId.GenerateNewId().ToString();
newRoomDoc.Room.RoomId = newId;
newRoomDoc.Room.CreatorPlayerId = (int)user.AccountId;
newRoomDoc.Room.Name = roomName;
foreach (var scene in newRoomDoc.Scenes)
{
scene.RoomId = newId;
scene.DataModifiedAt = DateTime.UtcNow;
}
newRoomDoc.VisitCount = 0;
newRoomDoc.CheerCount = 0;
newRoomDoc.FavoriteCount = 0;
await MongoDB.roomsCollection.InsertOneAsync(newRoomDoc);
return new
{
Result = 0,
RoomDetails = newRoomDoc
};
}
[ServerAPI.POST("/api/rooms/v1/roomRolePermissions")]
[ServerAPI.UseAuthorization]
public dynamic ReturnRoomRolePermissions(MongoDB.User user)
{
return Results.Ok();
}
}
}

37
routes/API/Settings.cs Normal file
View File

@@ -0,0 +1,37 @@
using MongoDB.Driver;
using Stella.Models;
namespace Stella.Routes.API
{
public class Settings
{
[ServerAPI.GET("/api/settings/v2/")]
[ServerAPI.UseAuthorization]
public List<SettingDTO> ReturnGetSettings(MongoDB.User user)
{
return user.OtherData.Settings;
}
[ServerAPI.POST("/api/settings/v2/set")]
[ServerAPI.UseAuthorization]
public async Task<IResult> ReturnSetSettings(HttpContext ctx, MongoDB.User user)
{
SettingDTO? incoming = await ctx.Request.GetJson<SettingDTO>();
var updateResult = await MongoDB.usersCollection.UpdateOneAsync(
u => u.AccountId == user.AccountId && u.OtherData.Settings.Any(s => s.Key == incoming.Key),
Builders<MongoDB.User>.Update.Set("OtherData.Settings.$.Value", incoming.Value)
);
if (updateResult.MatchedCount == 0)
{
await MongoDB.usersCollection.UpdateOneAsync(
u => u.AccountId == user.AccountId,
Builders<MongoDB.User>.Update.Push("OtherData.Settings", incoming)
);
}
return Results.Ok();
}
}
}

View File

@@ -0,0 +1,70 @@
using Stella.Models;
namespace Stella.Routes.API
{
public class VersionCheck
{
[ServerAPI.GET("/api/versioncheck/v2")]
public VersionCheckV2ResponseDTO ReturnVersionCheckV2(HttpContext ctx)
{
string? v = ctx.Request.Query["v"];
VersionCheckV2ResponseDTO response = new()
{
ValidVersion = false
};
if (v != BuildConstants.Version && v != BuildConstants.PCVersion)
{
response = new VersionCheckV2ResponseDTO
{
ValidVersion = false
};
}
return response;
}
[ServerAPI.GET("/api/versioncheck/v3")]
public VersionCheckV3ResponseDTO ReturnVersionCheckV3(HttpContext ctx)
{
string? v = ctx.Request.Query["v"];
VersionCheckV3ResponseDTO response = new()
{
ValidVersion = false
};
if (v != BuildConstants.Version && v != BuildConstants.PCVersion)
{
response = new VersionCheckV3ResponseDTO
{
ValidVersion = false
};
}
return response;
}
[ServerAPI.GET("/api/versioncheck/v4")]
public VersionCheckV4ResponseDTO ReturnVersionCheckV4(HttpContext ctx)
{
string? v = ctx.Request.Query["v"];
VersionCheckV4ResponseDTO response = new()
{
VersionStatus = VersionStatus.ValidForPlay
};
if (v != BuildConstants.Version && v != BuildConstants.PCVersion)
{
response = new VersionCheckV4ResponseDTO
{
VersionStatus = VersionStatus.ValidForMenu
};
}
return response;
}
}
}