♻️ No idea, but errors all gone

This commit is contained in:
2025-07-08 23:55:31 +08:00
parent 2c67472894
commit 63b2b989ba
74 changed files with 1551 additions and 1100 deletions

View File

@@ -2,7 +2,7 @@ using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Services;
using DysonNetwork.Sphere.Permission;
using DysonNetwork.Shared.Permission;
using DysonNetwork.Sphere.Publisher;
using DysonNetwork.Sphere.Storage;
using Microsoft.AspNetCore.Authorization;
@@ -33,7 +33,9 @@ public class PostController(
{
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Shared.Models.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var userFriends = currentUser is null
? []
: (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
var publisher = pubName == null ? null : await db.Publishers.FirstOrDefaultAsync(p => p.Name == pubName);
@@ -67,8 +69,10 @@ public class PostController(
public async Task<ActionResult<Post>> GetPost(Guid id)
{
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Shared.Models.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var currentUser = currentUserValue as Account;
var userFriends = currentUser is null
? []
: (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
var post = await db.Posts
@@ -99,8 +103,10 @@ public class PostController(
return BadRequest("Search query cannot be empty");
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Shared.Models.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var currentUser = currentUserValue as Account;
var userFriends = currentUser is null
? []
: (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
var queryable = db.Posts
@@ -136,8 +142,10 @@ public class PostController(
[FromQuery] int take = 20)
{
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Shared.Models.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var currentUser = currentUserValue as Account;
var userFriends = currentUser is null
? []
: (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
var parent = await db.Posts
@@ -264,9 +272,12 @@ public class PostController(
return BadRequest(err.Message);
}
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.PostCreate,
new Dictionary<string, object> { { "post_id", post.Id } }, Request
new Dictionary<string, object> { { "post_id", post.Id } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return post;
@@ -280,12 +291,12 @@ public class PostController(
[HttpPost("{id:guid}/reactions")]
[Authorize]
[RequiredPermissionAttribute("global", "posts.react")]
[RequiredPermission("global", "posts.react")]
public async Task<ActionResult<PostReaction>> ReactPost(Guid id, [FromBody] PostReactionRequest request)
{
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
if (currentUserValue is not Shared.Models.Account currentUser) return Unauthorized();
var userFriends = await rels.ListAccountFriends(currentUser);
if (currentUserValue is not Account currentUser) return Unauthorized();
var userFriends = (await rels.ListAccountFriends(currentUser)).Select(e => e.Id).ToList();
var userPublishers = await pub.GetUserPublishers(currentUser.Id);
var post = await db.Posts
@@ -319,9 +330,12 @@ public class PostController(
if (isRemoving) return NoContent();
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.PostReact,
new Dictionary<string, object> { { "post_id", post.Id }, { "reaction", request.Symbol } }, Request
new Dictionary<string, object> { { "post_id", post.Id }, { "reaction", request.Symbol } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return Ok(reaction);
@@ -368,9 +382,12 @@ public class PostController(
return BadRequest(err.Message);
}
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.PostUpdate,
new Dictionary<string, object> { { "post_id", post.Id } }, Request
new Dictionary<string, object> { { "post_id", post.Id } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return Ok(post);
@@ -392,9 +409,12 @@ public class PostController(
await ps.DeletePostAsync(post);
als.CreateActionLogFromRequest(
await als.CreateActionLogFromRequest(
ActionLogType.PostDelete,
new Dictionary<string, object> { { "post_id", post.Id } }, Request
new Dictionary<string, object> { { "post_id", post.Id } },
Request.HttpContext.Connection.RemoteIpAddress?.ToString(),
Request.Headers.UserAgent.ToString(),
currentUser
);
return NoContent();