mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-25 01:52:51 +00:00
Update CS models, deps
This commit is contained in:
1 parent
b2990b5a2e
commit
7dcccdcd6c
121 files changed
+1004
-854
No files matched your search
@@ -20,7 +20,7 @@ public class ChannelController(
|
||||
ISpacebarReplication replication
|
||||
) : ControllerBase {
|
||||
[HttpDelete("{id}")]
|
||||
public async Task DeleteById(string id) {
|
||||
public async Task DeleteById(long id) {
|
||||
(await auth.GetCurrentUserAsync(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
|
||||
// TODO: proper type
|
||||
await replication.SendAsync<Channel>(new() {
|
||||
@@ -35,7 +35,7 @@ public class ChannelController(
|
||||
|
||||
private async IAsyncEnumerable<AsyncActionResult> DeleteMessagesForChannel(
|
||||
// context
|
||||
string? guildId, string channelId, string authorId,
|
||||
long? guildId, long channelId, long authorId,
|
||||
// options
|
||||
int messageDeleteChunkSize = 100
|
||||
) {
|
||||
@@ -45,7 +45,7 @@ public class ChannelController(
|
||||
var messagesInChannel = _db.Messages.AsNoTracking().Count(m => m.AuthorId == authorId && m.ChannelId == channelId && m.GuildId == guildId);
|
||||
var remaining = messagesInChannel;
|
||||
while (true) {
|
||||
var messageIds = _db.Database.SqlQuery<string>($"""
|
||||
var messageIds = _db.Database.SqlQuery<long>($"""
|
||||
DELETE FROM messages
|
||||
WHERE id IN (
|
||||
SELECT id FROM messages
|
||||
@@ -67,7 +67,7 @@ public class ChannelController(
|
||||
ChannelId = channelId,
|
||||
MessageIds = messageIds,
|
||||
},
|
||||
Origin = "Admin API (GuildController.DeleteUser)",
|
||||
Origin = "Admin API (ChannelController.DeleteMessagesForChannel)",
|
||||
});
|
||||
|
||||
yield return new("BULK_DELETED", new {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ConfigController(ILogger<ConfigController> logger, SpacebarDbContex
|
||||
await Task.WhenAll(tasks);
|
||||
await replication.SendAsync(new() {
|
||||
Event = "SB_RELOAD_CONFIG",
|
||||
GuildId = "0",
|
||||
GuildId = 0,
|
||||
Origin = "Admin API (POST /Configuration)",
|
||||
});
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ConfigController(ILogger<ConfigController> logger, SpacebarDbContex
|
||||
|
||||
await replication.SendAsync(new() {
|
||||
Event = "SB_RELOAD_CONFIG",
|
||||
GuildId = "0",
|
||||
GuildId = 0,
|
||||
Origin = "Admin API (POST /Configuration/ReloadConfig)",
|
||||
});
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class GuildDiscoveryController(
|
||||
}
|
||||
|
||||
[HttpGet("{guildId}")]
|
||||
public async Task<DiscoverableGuildModel> GetDiscoverableGuild(string guildId, bool includeExcluded = false) {
|
||||
public async Task<DiscoverableGuildModel> GetDiscoverableGuild(long guildId, bool includeExcluded = false) {
|
||||
(await auth.GetCurrentUserAsync(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
|
||||
var discoverableGuilds = db.Guilds
|
||||
.AsNoTracking()
|
||||
@@ -131,7 +131,7 @@ public class GuildDiscoveryController(
|
||||
}
|
||||
|
||||
[HttpPatch("{guildId}")]
|
||||
public async Task<DiscoverableGuildModel> UpdateDiscoverableGuild(string guildId, [FromBody] DiscoverableGuildUpdateModel guildUpdateModel, bool includeExcluded = false) {
|
||||
public async Task<DiscoverableGuildModel> UpdateDiscoverableGuild(long guildId, [FromBody] DiscoverableGuildUpdateModel guildUpdateModel, bool includeExcluded = false) {
|
||||
(await auth.GetCurrentUserAsync(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
|
||||
var guild = await db.Guilds
|
||||
.AsNoTracking()
|
||||
|
||||
@@ -80,7 +80,7 @@ public class GuildController(
|
||||
}
|
||||
|
||||
[HttpPost("{id}/force_join")]
|
||||
public async Task<IActionResult> ForceJoinGuild([FromBody] ForceJoinRequest request, string id) {
|
||||
public async Task<IActionResult> ForceJoinGuild([FromBody] ForceJoinRequest request, long id) {
|
||||
(await auth.GetCurrentUserAsync(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
|
||||
|
||||
var guild = await db.Guilds.FindAsync(id);
|
||||
@@ -125,7 +125,7 @@ public class GuildController(
|
||||
var adminRole = roles.FirstOrDefault(r => r.Permissions == "8" || r.Permissions == "9"); // Administrator
|
||||
if (adminRole == null) {
|
||||
adminRole = new Role {
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
Id = Random.Shared.NextInt64(), // TODO: snowflakes
|
||||
GuildId = id,
|
||||
Name = "Instance administrator",
|
||||
Color = 0,
|
||||
@@ -152,7 +152,7 @@ public class GuildController(
|
||||
}
|
||||
|
||||
[HttpGet("{id}/delete")]
|
||||
public async IAsyncEnumerable<AsyncActionResult> DeleteUser(string id, [FromQuery] int messageDeleteChunkSize = 100) {
|
||||
public async IAsyncEnumerable<AsyncActionResult> DeleteUser(long id, [FromQuery] int messageDeleteChunkSize = 100) {
|
||||
(await auth.GetCurrentUserAsync(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
|
||||
|
||||
var user = await db.Users.FindAsync(id);
|
||||
@@ -182,7 +182,7 @@ public class GuildController(
|
||||
messages_per_channel = channels.ToDictionary(c => c.ChannelId, c => messages.Count(m => m.ChannelId == c.ChannelId))
|
||||
});
|
||||
var results = channels
|
||||
.Select(ctx => DeleteMessagesForChannel(ctx.GuildId, ctx.ChannelId!, id, messageDeleteChunkSize))
|
||||
.Select(ctx => DeleteMessagesForChannel(ctx.GuildId, ctx.ChannelId!.Value, id, messageDeleteChunkSize))
|
||||
.ToList();
|
||||
var a = AggregateAsyncEnumerablesWithoutOrder(results);
|
||||
await foreach (var result in a) {
|
||||
@@ -195,7 +195,7 @@ public class GuildController(
|
||||
|
||||
private async IAsyncEnumerable<AsyncActionResult> DeleteMessagesForChannel(
|
||||
// context
|
||||
string? guildId, string channelId, string authorId,
|
||||
long? guildId, long channelId, long authorId,
|
||||
// options
|
||||
int messageDeleteChunkSize = 100
|
||||
) {
|
||||
@@ -205,7 +205,7 @@ public class GuildController(
|
||||
var messagesInChannel = _db.Messages.AsNoTracking().Count(m => m.AuthorId == authorId && m.ChannelId == channelId && m.GuildId == guildId);
|
||||
var remaining = messagesInChannel;
|
||||
while (true) {
|
||||
var messageIds = _db.Database.SqlQuery<string>($"""
|
||||
var messageIds = _db.Database.SqlQuery<long>($"""
|
||||
DELETE FROM messages
|
||||
WHERE id IN (
|
||||
SELECT id FROM messages
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Spacebar.AdminApi.Controllers.Media;
|
||||
[Route("/media/user")]
|
||||
public class UserMediaController(ILogger<UserMediaController> logger, SpacebarDbContext db, SpacebarAspNetAuthenticationService auth, IServiceProvider sp) : ControllerBase {
|
||||
[HttpGet("{userId}/attachments")]
|
||||
public async IAsyncEnumerable<Attachment> GetAttachmentsByUser(string userId) {
|
||||
public async IAsyncEnumerable<Attachment> GetAttachmentsByUser(long userId) {
|
||||
(await auth.GetCurrentUserAsync(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
|
||||
|
||||
var db2 = sp.CreateScope().ServiceProvider.GetService<SpacebarDbContext>();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class IpcTestController(
|
||||
public async IAsyncEnumerable<string> Test() {
|
||||
(await auth.GetCurrentUserAsync(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
|
||||
|
||||
var guildId = "1006649183970562092";
|
||||
var guildId = 1006649183970562092;
|
||||
// var roleId = "1006706520514028812"; //Administrator
|
||||
var roleId = "1391303296148639051"; //Spacebar Maintainer
|
||||
// int color = 16711680; //Administrator
|
||||
|
||||
@@ -85,7 +85,7 @@ public class UserController(
|
||||
/// <param name="id">User ID</param>
|
||||
/// <returns>User object</returns>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<UserModel> GetById(string id) {
|
||||
public async Task<UserModel> GetById(long id) {
|
||||
(await auth.GetCurrentUserAsync(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
|
||||
|
||||
return await db.Users
|
||||
@@ -137,7 +137,7 @@ public class UserController(
|
||||
}
|
||||
|
||||
[HttpGet("{id}/delete")]
|
||||
public async IAsyncEnumerable<AsyncActionResult> DeleteUser(string id, [FromQuery] int messageDeleteChunkSize = 100) {
|
||||
public async IAsyncEnumerable<AsyncActionResult> DeleteUser(long id, [FromQuery] int messageDeleteChunkSize = 100) {
|
||||
(await auth.GetCurrentUserAsync(Request)).GetRights().AssertHasAllRights(SpacebarRights.Rights.OPERATOR);
|
||||
|
||||
var user = await db.Users.FindAsync(id);
|
||||
@@ -170,11 +170,11 @@ public class UserController(
|
||||
yield return new("STATS",
|
||||
new {
|
||||
total_messages = messages.Count(), total_channels = channels.Count,
|
||||
messages_per_channel = channels.ToDictionary(c => c.ChannelId, c => messages.Count(m => m.ChannelId == c.ChannelId))
|
||||
messages_per_channel = channels.ToDictionary(c => c.ChannelId!, c => messages.Count(m => m.ChannelId == c.ChannelId))
|
||||
});
|
||||
if (messages.Any()) {
|
||||
var results = channels
|
||||
.Select(ctx => DeleteMessagesForChannel(ctx.GuildId, ctx.ChannelId!, id, messageDeleteChunkSize))
|
||||
.Select(ctx => DeleteMessagesForChannel(ctx.GuildId, ctx.ChannelId!.Value, id, messageDeleteChunkSize))
|
||||
.ToList();
|
||||
var a = AggregateAsyncEnumerablesWithoutOrder(results);
|
||||
await foreach (var result in a) {
|
||||
@@ -195,7 +195,7 @@ public class UserController(
|
||||
|
||||
private async IAsyncEnumerable<AsyncActionResult> DeleteMessagesForChannel(
|
||||
// context
|
||||
string? guildId, string channelId, string authorId,
|
||||
long? guildId, long channelId, long authorId,
|
||||
// options
|
||||
int messageDeleteChunkSize = 100
|
||||
) {
|
||||
@@ -205,7 +205,7 @@ public class UserController(
|
||||
var messagesInChannel = _db.Messages.AsNoTracking().Count(m => m.AuthorId == authorId && m.ChannelId == channelId && m.GuildId == guildId);
|
||||
var remaining = messagesInChannel;
|
||||
while (true) {
|
||||
var messageIds = _db.Database.SqlQuery<string>($"""
|
||||
var messageIds = _db.Database.SqlQuery<long>($"""
|
||||
DELETE FROM messages
|
||||
WHERE id IN (
|
||||
SELECT id FROM messages
|
||||
|
||||
Reference in new issue
Block a user