💥 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,4 +1,4 @@
@page "/web/account/profile"
@page "//account/profile"
@model DysonNetwork.Sphere.Pages.Account.ProfileModel
@{
ViewData["Title"] = "Profile";

View File

@ -1,9 +1,9 @@
@page "/web/auth/challenge/{id:guid}"
@page "//auth/challenge/{id:guid}"
@model DysonNetwork.Sphere.Pages.Auth.ChallengeModel
@{
// This page is kept for backward compatibility
// It will automatically redirect to the new SelectFactor page
Response.Redirect($"/web/auth/challenge/{Model.Id}/select-factor");
Response.Redirect($"//auth/challenge/{Model.Id}/select-factor");
}
<div class="hero min-h-full bg-base-200">

View File

@ -1,4 +1,4 @@
@page "/web/auth/login"
@page "//auth/login"
@model DysonNetwork.Sphere.Pages.Auth.LoginModel
@{
ViewData["Title"] = "Login | Solar Network";

View File

@ -1,4 +1,4 @@
@page "/web/auth/challenge/{id:guid}/select-factor"
@page "//auth/challenge/{id:guid}/select-factor"
@using DysonNetwork.Sphere.Account
@model DysonNetwork.Sphere.Pages.Auth.SelectFactorModel
@{

View File

@ -1,4 +1,4 @@
@page "/web/auth/challenge/{id:guid}/verify/{factorId:guid}"
@page "//auth/challenge/{id:guid}/verify/{factorId:guid}"
@using DysonNetwork.Sphere.Account
@model DysonNetwork.Sphere.Pages.Auth.VerifyFactorModel
@{

View File

@ -0,0 +1,22 @@
@page "/posts/{PostId:guid}"
@model DysonNetwork.Sphere.Pages.Posts.PostDetailModel
@{
ViewData["Title"] = Model.Post?.Title + " | Solar Network";
}
<div class="container mx-auto p-4">
@if (Model.Post != null)
{
<h1 class="text-3xl font-bold mb-4">@Model.Post.Title</h1>
<p class="text-gray-600 mb-2">Created at: @Model.Post.CreatedAt</p>
<div class="prose lg:prose-xl">
<p>@Model.Post.Content</p>
</div>
}
else
{
<div class="alert alert-error">
<span>Post not found.</span>
</div>
}
</div>

View File

@ -0,0 +1,44 @@
using DysonNetwork.Sphere.Account;
using DysonNetwork.Sphere.Post;
using DysonNetwork.Sphere.Publisher;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace DysonNetwork.Sphere.Pages.Posts;
public class PostDetailModel(
AppDatabase db,
PublisherService pub,
RelationshipService rels
) : PageModel
{
[BindProperty(SupportsGet = true)]
public Guid PostId { get; set; }
public Post.Post? Post { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (PostId == Guid.Empty)
return NotFound();
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Sphere.Account.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
Post = await db.Posts
.Where(e => e.Id == PostId)
.Include(e => e.Publisher)
.Include(e => e.Tags)
.Include(e => e.Categories)
.FilterWithVisibility(currentUser, userFriends, userPublishers)
.FirstOrDefaultAsync();
if (Post == null)
return NotFound();
return Page();
}
}

View File

@ -26,7 +26,7 @@
@if (Context.Request.Cookies.TryGetValue(AuthConstants.CookieTokenName, out _))
{
<li class="tooltip tooltip-bottom" data-tip="Profile">
<a href="/web/account/profile">
<a href="//account/profile">
<span class="material-symbols-outlined">account_circle</span>
</a>
</li>
@ -43,7 +43,7 @@
else
{
<li class="tooltip tooltip-bottom" data-tip="Login">
<a href="/web/auth/login"><span class="material-symbols-outlined">login</span></a>
<a href="//auth/login"><span class="material-symbols-outlined">login</span></a>
</li>
}
</ul>