diff --git a/DysonNetwork.Sphere/Auth/UserInfoMiddleware.cs b/DysonNetwork.Sphere/Auth/UserInfoMiddleware.cs index d49618b..effee0c 100644 --- a/DysonNetwork.Sphere/Auth/UserInfoMiddleware.cs +++ b/DysonNetwork.Sphere/Auth/UserInfoMiddleware.cs @@ -14,6 +14,8 @@ public class UserInfoMiddleware(RequestDelegate next, IMemoryCache cache) { user = await db.Accounts .Include(e => e.Profile) + .Include(e => e.Profile.Picture) + .Include(e => e.Profile.Background) .Where(e => e.Id == userId) .FirstOrDefaultAsync(); diff --git a/DysonNetwork.Sphere/Post/PostController.cs b/DysonNetwork.Sphere/Post/PostController.cs index eca8181..cd12eb1 100644 --- a/DysonNetwork.Sphere/Post/PostController.cs +++ b/DysonNetwork.Sphere/Post/PostController.cs @@ -20,12 +20,15 @@ public class PostController(AppDatabase db, PostService ps, IEnforcer enforcer) .CountAsync(); var posts = await db.Posts .Include(e => e.Publisher) + .Include(e => e.Publisher.Picture) + .Include(e => e.Publisher.Background) .Include(e => e.ThreadedPost) .Include(e => e.ForwardedPost) .Include(e => e.Attachments) .Include(e => e.Categories) .Include(e => e.Tags) .FilterWithVisibility(currentUser, isListing: true) + .OrderByDescending(e => e.PublishedAt ?? e.CreatedAt) .Skip(offset) .Take(take) .ToListAsync(); @@ -44,6 +47,8 @@ public class PostController(AppDatabase db, PostService ps, IEnforcer enforcer) var post = await db.Posts .Where(e => e.Id == id) .Include(e => e.Publisher) + .Include(e => e.Publisher.Picture) + .Include(e => e.Publisher.Background) .Include(e => e.RepliedPost) .Include(e => e.ThreadedPost) .Include(e => e.ForwardedPost) @@ -75,12 +80,15 @@ public class PostController(AppDatabase db, PostService ps, IEnforcer enforcer) var posts = await db.Posts .Where(e => e.RepliedPostId == id) .Include(e => e.Publisher) + .Include(e => e.Publisher.Picture) + .Include(e => e.Publisher.Background) .Include(e => e.ThreadedPost) .Include(e => e.ForwardedPost) .Include(e => e.Attachments) .Include(e => e.Categories) .Include(e => e.Tags) .FilterWithVisibility(currentUser, isListing: true) + .OrderByDescending(e => e.PublishedAt ?? e.CreatedAt) .Skip(offset) .Take(take) .ToListAsync(); @@ -172,6 +180,8 @@ public class PostController(AppDatabase db, PostService ps, IEnforcer enforcer) var post = await db.Posts .Where(e => e.Id == id) .Include(e => e.Publisher) + .Include(e => e.Publisher.Picture) + .Include(e => e.Publisher.Background) .Include(e => e.Attachments) .Include(e => e.Categories) .Include(e => e.Tags) diff --git a/DysonNetwork.Sphere/Post/PostService.cs b/DysonNetwork.Sphere/Post/PostService.cs index 3e1002b..58a12e1 100644 --- a/DysonNetwork.Sphere/Post/PostService.cs +++ b/DysonNetwork.Sphere/Post/PostService.cs @@ -18,7 +18,11 @@ public class PostService(AppDatabase db, FileService fs) if (post.PublishedAt.Value.ToDateTimeUtc() < DateTime.UtcNow) throw new InvalidOperationException("Cannot create the post which published in the past."); } - + else + { + post.PublishedAt = Instant.FromDateTimeUtc(DateTime.UtcNow); + } + if (attachments is not null) { post.Attachments = await db.Files.Where(e => attachments.Contains(e.Id)).ToListAsync(); diff --git a/DysonNetwork.Sphere/Program.cs b/DysonNetwork.Sphere/Program.cs index d17da85..70298f0 100644 --- a/DysonNetwork.Sphere/Program.cs +++ b/DysonNetwork.Sphere/Program.cs @@ -26,6 +26,7 @@ using File = System.IO.File; var builder = WebApplication.CreateBuilder(args); builder.Host.UseContentRoot(Directory.GetCurrentDirectory()); +builder.WebHost.ConfigureKestrel(options => options.Limits.MaxRequestBodySize = long.MaxValue); // Add services to the container. @@ -166,6 +167,8 @@ app.UseForwardedHeaders(new ForwardedHeadersOptions app.UseCors(opts => opts.SetIsOriginAllowed(_ => true) + .WithExposedHeaders("X-Total") + .WithHeaders("X-Total") .AllowCredentials() .AllowAnyHeader() .AllowAnyMethod() diff --git a/DysonNetwork.Sphere/Storage/FileService.cs b/DysonNetwork.Sphere/Storage/FileService.cs index b744cd7..b0a96dd 100644 --- a/DysonNetwork.Sphere/Storage/FileService.cs +++ b/DysonNetwork.Sphere/Storage/FileService.cs @@ -81,17 +81,25 @@ public class FileService(AppDatabase db, IConfiguration configuration) break; case "video": case "audio": - var mediaInfo = await FFProbe.AnalyseAsync(stream); - file.FileMeta = new Dictionary + try { - ["duration"] = mediaInfo.Duration.TotalSeconds, - ["format_name"] = mediaInfo.Format.FormatName, - ["format_long_name"] = mediaInfo.Format.FormatLongName, - ["start_time"] = mediaInfo.Format.StartTime.ToString(), - ["bit_rate"] = mediaInfo.Format.BitRate.ToString(CultureInfo.InvariantCulture), - ["tags"] = mediaInfo.Format.Tags ?? [], - ["chapters"] = mediaInfo.Chapters, - }; + var mediaInfo = await FFProbe.AnalyseAsync(stream); + file.FileMeta = new Dictionary + { + ["duration"] = mediaInfo.Duration.TotalSeconds, + ["format_name"] = mediaInfo.Format.FormatName, + ["format_long_name"] = mediaInfo.Format.FormatLongName, + ["start_time"] = mediaInfo.Format.StartTime.ToString(), + ["bit_rate"] = mediaInfo.Format.BitRate.ToString(CultureInfo.InvariantCulture), + ["tags"] = mediaInfo.Format.Tags ?? [], + ["chapters"] = mediaInfo.Chapters, + }; + } + catch + { + // ignored + } + break; } diff --git a/DysonNetwork.sln.DotSettings.user b/DysonNetwork.sln.DotSettings.user index 3a5abba..706b819 100644 --- a/DysonNetwork.sln.DotSettings.user +++ b/DysonNetwork.sln.DotSettings.user @@ -25,6 +25,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded