🗑️ Remove built-in frontend serving code

This commit is contained in:
2025-09-19 00:14:37 +08:00
parent 1e374a73c7
commit 634958ffc5
25 changed files with 11 additions and 352 deletions

View File

@@ -1,72 +0,0 @@
using System.Net;
using DysonNetwork.Shared.PageData;
using DysonNetwork.Shared.Proto;
using DysonNetwork.Sphere.Post;
using Microsoft.EntityFrameworkCore;
using OpenGraphNet;
namespace DysonNetwork.Sphere.PageData;
public class PostPageData(
AppDatabase db,
AccountService.AccountServiceClient accounts,
Publisher.PublisherService pub,
PostService ps,
IConfiguration configuration
)
: IPageDataProvider
{
private readonly string _siteUrl = configuration["SiteUrl"]!;
public bool CanHandlePath(PathString path) =>
path.StartsWithSegments("/posts");
public async Task<IDictionary<string, object?>> GetAppDataAsync(HttpContext context)
{
var path = context.Request.Path.Value!;
var startIndex = "/posts/".Length;
var endIndex = path.IndexOf('/', startIndex);
var slug = endIndex == -1 ? path[startIndex..] : path.Substring(startIndex, endIndex - startIndex);
slug = WebUtility.UrlDecode(slug);
var postId = Guid.TryParse(slug, out var postIdGuid) ? postIdGuid : Guid.Empty;
if (postId == Guid.Empty) return new Dictionary<string, object?>();
context.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Account;
List<Guid> userFriends = [];
if (currentUser != null)
{
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 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 new Dictionary<string, object?>();
post = await ps.LoadPostInfo(post, currentUser);
var og = OpenGraph.MakeGraph(
title: post.Title ?? $"Post from {post.Publisher.Name}",
type: "article",
image: $"{_siteUrl}/cgi/drive/files/{post.Publisher.Background?.Id}?original=true",
url: $"{_siteUrl}/@{slug}",
description: post.Description ?? (post.Content?.Length > 80 ? post.Content?[..80] : post.Content) ?? "Posted with some media",
siteName: "Solar Network"
);
return new Dictionary<string, object?>()
{
["Post"] = post,
["OpenGraph"] = og
};
}
}

View File

@@ -1,9 +1,7 @@
using DysonNetwork.Shared.Auth;
using DysonNetwork.Shared.Http;
using DysonNetwork.Shared.PageData;
using DysonNetwork.Shared.Registry;
using DysonNetwork.Sphere;
using DysonNetwork.Sphere.PageData;
using DysonNetwork.Sphere.Startup;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileProviders;
@@ -35,8 +33,6 @@ builder.Services.AddAppBusinessServices(builder.Configuration);
// Add scheduled jobs
builder.Services.AddAppScheduledJobs();
builder.Services.AddTransient<IPageDataProvider, PostPageData>();
var app = builder.Build();
app.MapDefaultEndpoints();
@@ -51,12 +47,4 @@ using (var scope = app.Services.CreateScope())
// Configure application middleware pipeline
app.ConfigureAppMiddleware(builder.Configuration);
app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(app.Environment.ContentRootPath, "wwwroot", "dist"))
});
app.MapPages(Path.Combine(app.Environment.WebRootPath, "dist", "index.html"));
app.Run();