🐛 Fix missing file permission creation

This commit is contained in:
2026-01-12 19:32:50 +08:00
parent 7085f43e54
commit c11bf579c4
12 changed files with 158 additions and 3 deletions

View File

@@ -163,6 +163,14 @@ public partial class PostService(
post.Attachments = attachments
.Select(id => post.Attachments.First(a => a.Id == id))
.ToList();
if (post.Visibility == Shared.Models.PostVisibility.Public)
{
foreach (var attachment in post.Attachments)
{
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
}
}
}
if (tags is not null)
@@ -326,9 +334,25 @@ public partial class PostService(
throw new InvalidOperationException("Categories contains one or more categories that wasn't exists.");
}
var oldVisibility = post.Visibility;
db.Update(post);
await db.SaveChangesAsync();
if (post.Visibility == Shared.Models.PostVisibility.Public && oldVisibility != Shared.Models.PostVisibility.Public)
{
foreach (var attachment in post.Attachments)
{
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = attachment.Id });
}
}
else if (oldVisibility == Shared.Models.PostVisibility.Public && post.Visibility != Shared.Models.PostVisibility.Public)
{
foreach (var attachment in post.Attachments)
{
await files.UnsetFilePublicAsync(new UnsetFilePublicRequest { FileId = attachment.Id });
}
}
// Process link preview in the background to avoid delaying post update
_ = Task.Run(async () => await CreateLinkPreviewAsync(post));