Featured post

This commit is contained in:
2025-07-31 11:27:52 +08:00
parent 8e6e3e6289
commit 49fe70b0aa
2 changed files with 21 additions and 4 deletions

View File

@@ -19,7 +19,7 @@ public class AuthController(
IConfiguration configuration
) : ControllerBase
{
private readonly string CookieDomain = configuration["AuthToken:CookieDomain"]!;
private readonly string _cookieDomain = configuration["AuthToken:CookieDomain"]!;
public class ChallengeRequest
{
@@ -257,7 +257,7 @@ public class AuthController(
HttpOnly = true,
Secure = true,
SameSite = SameSiteMode.Lax,
Domain = CookieDomain,
Domain = _cookieDomain,
Expires = DateTime.UtcNow.AddDays(30)
});
@@ -281,7 +281,7 @@ public class AuthController(
{
Response.Cookies.Delete(AuthConstants.CookieTokenName, new CookieOptions
{
Domain = CookieDomain,
Domain = _cookieDomain,
HttpOnly = true,
Secure = true,
SameSite = SameSiteMode.Lax

View File

@@ -119,7 +119,8 @@ public class PostController(
var friendsResponse = await accounts.ListFriendsAsync(new ListRelationshipSimpleRequest
{ AccountId = currentUser.Id });
userFriends = friendsResponse.AccountsId.Select(Guid.Parse).ToList();
}
}
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(Guid.Parse(currentUser.Id));
var queryable = db.Posts
@@ -150,6 +151,22 @@ public class PostController(
return Ok(posts);
}
[HttpGet("{id:guid}/replies/featured")]
public async Task<ActionResult<Post>> GetFeaturedReply(Guid id)
{
var now = SystemClock.Instance.GetCurrentInstant();
var post = await db.Posts
.Where(e => e.RepliedPostId == id)
.OrderByDescending(p =>
p.Upvotes * 2 -
p.Downvotes +
((p.CreatedAt - now).TotalMinutes < 60 ? 5 : 0)
)
.FirstOrDefaultAsync();
if (post is null) return NotFound();
return await ps.LoadPostInfo(post);
}
[HttpGet("{id:guid}/replies")]
public async Task<ActionResult<List<Post>>> ListReplies(Guid id, [FromQuery] int offset = 0,
[FromQuery] int take = 20)