💥 Add /api prefix for json endpoints with redirect

This commit is contained in:
2025-07-10 14:18:02 +08:00
parent 1f2cdb146d
commit fc6edd7378
43 changed files with 217 additions and 41 deletions

View File

@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using DysonNetwork.Sphere.Account;
using DysonNetwork.Sphere.Pages.Posts;
using DysonNetwork.Sphere.Permission;
using DysonNetwork.Sphere.Publisher;
using DysonNetwork.Sphere.Storage;
@ -13,7 +14,7 @@ using NpgsqlTypes;
namespace DysonNetwork.Sphere.Post;
[ApiController]
[Route("/posts")]
[Route("/api/posts")]
public class PostController(
AppDatabase db,
PostService ps,
@ -65,6 +66,9 @@ public class PostController(
[HttpGet("{id:guid}")]
public async Task<ActionResult<Post>> GetPost(Guid id)
{
if (HttpContext.Items["IsWebPage"] as bool? ?? true)
return RedirectToPage("/Posts/PostDetail", new { PostId = id });
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Account.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);