:drunk: Write shit code trying to split up the Auth (WIP)

This commit is contained in:
2025-07-06 12:58:18 +08:00
parent 5757526ea5
commit 6a3d04af3d
224 changed files with 1889 additions and 36885 deletions

View File

@ -38,19 +38,7 @@ public class AutoCompletionController(AppDatabase db)
private async Task<List<CompletionItem>> GetAccountCompletions(string searchTerm)
{
return await db.Accounts
.Where(a => EF.Functions.ILike(a.Name, $"%{searchTerm}%"))
.OrderBy(a => a.Name)
.Take(10)
.Select(a => new CompletionItem
{
Id = a.Id.ToString(),
DisplayName = a.Name,
SecondaryText = a.Nick,
Type = "account",
Data = a
})
.ToListAsync();
return await passClient.GetAccountCompletions(searchTerm);
}
private async Task<List<CompletionItem>> GetStickerCompletions(string searchTerm)

View File

@ -1,4 +1,5 @@
using System.Net.WebSockets;
using DysonNetwork.Common.Models;
using DysonNetwork.Sphere.Chat;
using DysonNetwork.Sphere.Storage;
using Microsoft.EntityFrameworkCore;
@ -42,7 +43,7 @@ public class MessageReadHandler(
return;
}
var sender = await crs.GetRoomMember(currentUser.Id, request.ChatRoomId);
var sender = await crs.GetRoomMember(currentUserId, request.ChatRoomId);
if (sender is null)
{
await socket.SendAsync(

View File

@ -33,7 +33,7 @@ public class MessageTypingHandler(ChatRoomService crs) : IWebSocketPacketHandler
return;
}
var sender = await crs.GetRoomMember(currentUser.Id, request.ChatRoomId);
var sender = await crs.GetRoomMember(currentUserId, request.ChatRoomId);
if (sender is null)
{
await socket.SendAsync(

View File

@ -32,7 +32,7 @@ public class MessagesSubscribeHandler(ChatRoomService crs) : IWebSocketPacketHan
return;
}
var sender = await crs.GetRoomMember(currentUser.Id, request.ChatRoomId);
var sender = await crs.GetRoomMember(currentUserId, request.ChatRoomId);
if (sender is null)
{
await socket.SendAsync(

View File

@ -8,7 +8,7 @@ public class MessagesUnsubscribeHandler() : IWebSocketPacketHandler
public string PacketType => "messages.unsubscribe";
public Task HandleAsync(
Account.Account currentUser,
Guid currentUserId,
string deviceId,
WebSocketPacket packet,
WebSocket socket,

View File

@ -5,5 +5,5 @@ namespace DysonNetwork.Sphere.Connection;
public interface IWebSocketPacketHandler
{
string PacketType { get; }
Task HandleAsync(Account.Account currentUser, string deviceId, WebSocketPacket packet, WebSocket socket, WebSocketService srv);
Task HandleAsync(Guid currentUserId, string deviceId, WebSocketPacket packet, WebSocket socket, WebSocketService srv);
}

View File

@ -104,7 +104,8 @@ public class WebFeedController(WebFeedService webFeed, PublisherService ps) : Co
[Authorize]
public async Task<ActionResult> Scrap([FromRoute] string pubName, Guid id)
{
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
var currentUser = await passClient.GetAccountByIdAsync(User.GetUserId());
if (currentUser is null) return Unauthorized();
var publisher = await ps.GetPublisherByName(pubName);
if (publisher is null) return NotFound();

View File

@ -1,6 +1,7 @@
using System.Globalization;
using AngleSharp;
using AngleSharp.Dom;
using DysonNetwork.Common.Services;
using DysonNetwork.Sphere.Storage;
using HtmlAgilityPack;

View File

@ -91,7 +91,7 @@ public class WebSocketController(WebSocketService ws, ILogger<WebSocketContext>
);
var packet = WebSocketPacket.FromBytes(buffer[..receiveResult.Count]);
_ = ws.HandlePacket(currentUser, connectionKey.DeviceId, packet, webSocket);
_ = ws.HandlePacket(currentUserId, connectionKey.DeviceId, packet, webSocket);
}
}
catch (OperationCanceledException)

View File

@ -111,7 +111,7 @@ public class WebSocketService
{
if (_handlerMap.TryGetValue(packet.Type, out var handler))
{
await handler.HandleAsync(currentUser, deviceId, packet, socket, this);
await handler.HandleAsync(currentUserId, deviceId, packet, socket, this);
return;
}