♻️ Move most of models to the Shared package

This commit is contained in:
2025-07-06 22:34:52 +08:00
parent cb4acbb3fc
commit 65450e8511
170 changed files with 679 additions and 101121 deletions

View File

@ -1,4 +1,5 @@
using System.Net.WebSockets;
using DysonNetwork.Shared.Models;
using DysonNetwork.Sphere.Chat;
using DysonNetwork.Sphere.Storage;
using Microsoft.EntityFrameworkCore;
@ -19,7 +20,7 @@ public class MessageReadHandler(
public const string ChatMemberCacheKey = "ChatMember_{0}_{1}";
public async Task HandleAsync(
Account.Account currentUser,
Shared.Models.Account currentUser,
string deviceId,
WebSocketPacket packet,
WebSocket socket,

View File

@ -10,7 +10,7 @@ public class MessageTypingHandler(ChatRoomService crs) : IWebSocketPacketHandler
public string PacketType => "messages.typing";
public async Task HandleAsync(
Account.Account currentUser,
Shared.Models.Account currentUser,
string deviceId,
WebSocketPacket packet,
WebSocket socket,

View File

@ -9,7 +9,7 @@ public class MessagesSubscribeHandler(ChatRoomService crs) : IWebSocketPacketHan
public string PacketType => "messages.subscribe";
public async Task HandleAsync(
Account.Account currentUser,
Shared.Models.Account currentUser,
string deviceId,
WebSocketPacket packet,
WebSocket socket,

View File

@ -8,7 +8,7 @@ public class MessagesUnsubscribeHandler() : IWebSocketPacketHandler
public string PacketType => "messages.unsubscribe";
public Task HandleAsync(
Account.Account currentUser,
Shared.Models.Account currentUser,
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(Shared.Models.Account currentUser, string deviceId, WebSocketPacket packet, WebSocket socket, WebSocketService srv);
}

View File

@ -40,7 +40,7 @@ public class WebFeed : ModelBase
[Column(TypeName = "jsonb")] public WebFeedConfig Config { get; set; } = new();
public Guid PublisherId { get; set; }
public Publisher.Publisher Publisher { get; set; } = null!;
public Shared.Models.Publisher Publisher { get; set; } = null!;
[JsonIgnore] public ICollection<WebArticle> Articles { get; set; } = new List<WebArticle>();
}

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using DysonNetwork.Shared.Models;
using DysonNetwork.Sphere.Publisher;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@ -43,7 +44,7 @@ public class WebFeedController(WebFeedService webFeed, PublisherService ps) : Co
[Authorize]
public async Task<IActionResult> CreateWebFeed([FromRoute] string pubName, [FromBody] WebFeedRequest request)
{
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
if (string.IsNullOrWhiteSpace(request.Url) || string.IsNullOrWhiteSpace(request.Title))
return BadRequest("Url and title are required");
@ -62,7 +63,7 @@ public class WebFeedController(WebFeedService webFeed, PublisherService ps) : Co
[Authorize]
public async Task<IActionResult> UpdateFeed([FromRoute] string pubName, Guid id, [FromBody] WebFeedRequest request)
{
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
var publisher = await ps.GetPublisherByName(pubName);
if (publisher is null) return NotFound();
@ -82,7 +83,7 @@ public class WebFeedController(WebFeedService webFeed, PublisherService ps) : Co
[Authorize]
public async Task<IActionResult> DeleteFeed([FromRoute] string pubName, Guid id)
{
if (HttpContext.Items["CurrentUser"] is not Account.Account currentUser) return Unauthorized();
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
var publisher = await ps.GetPublisherByName(pubName);
if (publisher is null) return NotFound();
@ -104,7 +105,7 @@ 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();
if (HttpContext.Items["CurrentUser"] is not Shared.Models.Account currentUser) return Unauthorized();
var publisher = await ps.GetPublisherByName(pubName);
if (publisher is null) return NotFound();

View File

@ -11,7 +11,7 @@ public class WebFeedService(
WebReaderService webReaderService
)
{
public async Task<WebFeed> CreateWebFeedAsync(Publisher.Publisher publisher,
public async Task<WebFeed> CreateWebFeedAsync(Shared.Models.Publisher publisher,
WebFeedController.WebFeedRequest request)
{
var feed = new WebFeed

View File

@ -1,5 +1,6 @@
using System.Collections.Concurrent;
using System.Net.WebSockets;
using DysonNetwork.Shared.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
@ -18,8 +19,8 @@ public class WebSocketController(WebSocketService ws, ILogger<WebSocketContext>
{
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
HttpContext.Items.TryGetValue("CurrentSession", out var currentSessionValue);
if (currentUserValue is not Account.Account currentUser ||
currentSessionValue is not Auth.Session currentSession)
if (currentUserValue is not Shared.Models.Account currentUser ||
currentSessionValue is not Session currentSession)
{
HttpContext.Response.StatusCode = StatusCodes.Status401Unauthorized;
return;
@ -69,7 +70,7 @@ public class WebSocketController(WebSocketService ws, ILogger<WebSocketContext>
private async Task _ConnectionEventLoop(
string deviceId,
Account.Account currentUser,
Shared.Models.Account currentUser,
WebSocket webSocket,
CancellationToken cancellationToken
)

View File

@ -106,7 +106,7 @@ public class WebSocketService
}
}
public async Task HandlePacket(Account.Account currentUser, string deviceId, WebSocketPacket packet,
public async Task HandlePacket(Shared.Models.Account currentUser, string deviceId, WebSocketPacket packet,
WebSocket socket)
{
if (_handlerMap.TryGetValue(packet.Type, out var handler))