🐛 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

@@ -45,6 +45,9 @@ public class CustomAppService(
if (picture is null)
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
app.Picture = SnCloudFileReferenceObject.FromProtoValue(picture);
if (request.Status == Shared.Models.CustomAppStatus.Production)
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.PictureId });
}
if (request.BackgroundId is not null)
{
@@ -54,6 +57,9 @@ public class CustomAppService(
if (background is null)
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
app.Background = SnCloudFileReferenceObject.FromProtoValue(background);
if (request.Status == Shared.Models.CustomAppStatus.Production)
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.BackgroundId });
}
db.CustomApps.Add(app);
@@ -164,6 +170,7 @@ public class CustomAppService(
public async Task<SnCustomApp?> UpdateAppAsync(SnCustomApp app, CustomAppController.CustomAppRequest request)
{
var oldStatus = app.Status;
if (request.Slug is not null)
app.Slug = request.Slug;
if (request.Name is not null)
@@ -188,6 +195,9 @@ public class CustomAppService(
if (picture is null)
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
app.Picture = SnCloudFileReferenceObject.FromProtoValue(picture);
if (app.Status == Shared.Models.CustomAppStatus.Production)
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.PictureId });
}
if (request.BackgroundId is not null)
{
@@ -197,11 +207,29 @@ public class CustomAppService(
if (background is null)
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
app.Background = SnCloudFileReferenceObject.FromProtoValue(background);
if (app.Status == Shared.Models.CustomAppStatus.Production)
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = request.BackgroundId });
}
db.Update(app);
await db.SaveChangesAsync();
if (oldStatus != Shared.Models.CustomAppStatus.Production && app.Status == Shared.Models.CustomAppStatus.Production)
{
if (app.Picture is not null)
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = app.Picture.Id });
if (app.Background is not null)
await files.SetFilePublicAsync(new SetFilePublicRequest { FileId = app.Background.Id });
}
else if (oldStatus == Shared.Models.CustomAppStatus.Production && app.Status != Shared.Models.CustomAppStatus.Production)
{
if (app.Picture is not null)
await files.UnsetFilePublicAsync(new UnsetFilePublicRequest { FileId = app.Picture.Id });
if (app.Background is not null)
await files.UnsetFilePublicAsync(new UnsetFilePublicRequest { FileId = app.Background.Id });
}
return app;
}