diff --git a/DysonNetwork.Develop/Identity/CustomAppService.cs b/DysonNetwork.Develop/Identity/CustomAppService.cs index 043068c3..fde3f80e 100644 --- a/DysonNetwork.Develop/Identity/CustomAppService.cs +++ b/DysonNetwork.Develop/Identity/CustomAppService.cs @@ -8,7 +8,6 @@ namespace DysonNetwork.Develop.Identity; public class CustomAppService( AppDatabase db, - FileReferenceService.FileReferenceServiceClient fileRefs, FileService.FileServiceClient files ) { @@ -46,16 +45,6 @@ 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); - - // Create a new reference - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - FileId = picture.Id, - Usage = "custom-apps.picture", - ResourceId = app.ResourceIdentifier - } - ); } if (request.BackgroundId is not null) { @@ -65,16 +54,6 @@ 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); - - // Create a new reference - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - FileId = background.Id, - Usage = "custom-apps.background", - ResourceId = app.ResourceIdentifier - } - ); } db.CustomApps.Add(app); @@ -209,16 +188,6 @@ 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); - - // Create a new reference - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - FileId = picture.Id, - Usage = "custom-apps.picture", - ResourceId = app.ResourceIdentifier - } - ); } if (request.BackgroundId is not null) { @@ -228,16 +197,6 @@ 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); - - // Create a new reference - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - FileId = background.Id, - Usage = "custom-apps.background", - ResourceId = app.ResourceIdentifier - } - ); } db.Update(app); @@ -257,12 +216,6 @@ public class CustomAppService( db.CustomApps.Remove(app); await db.SaveChangesAsync(); - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { - ResourceId = app.ResourceIdentifier - } - ); - return true; } } \ No newline at end of file diff --git a/DysonNetwork.Drive/Storage/FileServiceGrpc.cs b/DysonNetwork.Drive/Storage/FileServiceGrpc.cs index ab3a5c31..a503ce95 100644 --- a/DysonNetwork.Drive/Storage/FileServiceGrpc.cs +++ b/DysonNetwork.Drive/Storage/FileServiceGrpc.cs @@ -41,27 +41,6 @@ namespace DysonNetwork.Drive.Storage return new Empty(); } - public override async Task LoadFromReference( - LoadFromReferenceRequest request, - ServerCallContext context - ) - { - // Assuming CloudFileReferenceObject is a simple class/struct that holds an ID - // You might need to define this or adjust the LoadFromReference method in FileService - var references = request.ReferenceIds.Select(id => new SnCloudFileReferenceObject { Id = id }).ToList(); - var files = await fileService.LoadFromReference(references); - var response = new LoadFromReferenceResponse(); - response.Files.AddRange(files.Where(f => f != null).Select(f => f!.ToProtoValue())); - return response; - } - - public override async Task IsReferenced(IsReferencedRequest request, - ServerCallContext context) - { - var isReferenced = await fileService.IsReferencedAsync(request.FileId); - return new IsReferencedResponse { IsReferenced = isReferenced }; - } - public override async Task PurgeCache(PurgeCacheRequest request, ServerCallContext context) { await fileService._PurgeCacheAsync(request.FileId); diff --git a/DysonNetwork.Messager/Chat/ChatRoomController.cs b/DysonNetwork.Messager/Chat/ChatRoomController.cs index 83da96b5..5bcf0d19 100644 --- a/DysonNetwork.Messager/Chat/ChatRoomController.cs +++ b/DysonNetwork.Messager/Chat/ChatRoomController.cs @@ -21,7 +21,6 @@ public class ChatRoomController( RemoteRealmService rs, AccountService.AccountServiceClient accounts, FileService.FileServiceClient files, - FileReferenceService.FileReferenceServiceClient fileRefs, ActionLogService.ActionLogServiceClient als, RingService.RingServiceClient pusher, RemoteAccountService remoteAccountsHelper @@ -220,13 +219,6 @@ public class ChatRoomController( var fileResponse = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId }); if (fileResponse == null) return BadRequest("Invalid picture id, unable to find the file on cloud."); chatRoom.Picture = SnCloudFileReferenceObject.FromProtoValue(fileResponse); - - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = fileResponse.Id, - Usage = "chatroom.picture", - ResourceId = chatRoom.ResourceIdentifier, - }); } catch (RpcException ex) when (ex.StatusCode == Grpc.Core.StatusCode.NotFound) { @@ -241,13 +233,6 @@ public class ChatRoomController( var fileResponse = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId }); if (fileResponse == null) return BadRequest("Invalid background id, unable to find the file on cloud."); chatRoom.Background = SnCloudFileReferenceObject.FromProtoValue(fileResponse); - - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = fileResponse.Id, - Usage = "chatroom.background", - ResourceId = chatRoom.ResourceIdentifier, - }); } catch (RpcException ex) when (ex.StatusCode == Grpc.Core.StatusCode.NotFound) { @@ -258,28 +243,6 @@ public class ChatRoomController( db.ChatRooms.Add(chatRoom); await db.SaveChangesAsync(); - var chatRoomResourceId = $"chatroom:{chatRoom.Id}"; - - if (chatRoom.Picture is not null) - { - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = chatRoom.Picture.Id, - Usage = "chat.room.picture", - ResourceId = chatRoomResourceId - }); - } - - if (chatRoom.Background is not null) - { - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = chatRoom.Background.Id, - Usage = "chat.room.background", - ResourceId = chatRoomResourceId - }); - } - _ = als.CreateActionLogAsync(new CreateActionLogRequest { Action = "chatrooms.create", @@ -329,21 +292,6 @@ public class ChatRoomController( var fileResponse = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId }); if (fileResponse == null) return BadRequest("Invalid picture id, unable to find the file on cloud."); - // Remove old references for pictures - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { - ResourceId = chatRoom.ResourceIdentifier, - Usage = "chat.room.picture" - }); - - // Add a new reference - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = fileResponse.Id, - Usage = "chat.room.picture", - ResourceId = chatRoom.ResourceIdentifier - }); - chatRoom.Picture = SnCloudFileReferenceObject.FromProtoValue(fileResponse); } catch (RpcException ex) when (ex.StatusCode == Grpc.Core.StatusCode.NotFound) @@ -359,21 +307,6 @@ public class ChatRoomController( var fileResponse = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId }); if (fileResponse == null) return BadRequest("Invalid background id, unable to find the file on cloud."); - // Remove old references for backgrounds - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { - ResourceId = chatRoom.ResourceIdentifier, - Usage = "chat.room.background" - }); - - // Add a new reference - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = fileResponse.Id, - Usage = "chat.room.background", - ResourceId = chatRoom.ResourceIdentifier - }); - chatRoom.Background = SnCloudFileReferenceObject.FromProtoValue(fileResponse); } catch (RpcException ex) when (ex.StatusCode == Grpc.Core.StatusCode.NotFound) @@ -427,14 +360,6 @@ public class ChatRoomController( else if (chatRoom.AccountId != accountId) return StatusCode(403, "You need be the owner to update the chat."); - var chatRoomResourceId = $"chatroom:{chatRoom.Id}"; - - // Delete all file references for this chat room - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { - ResourceId = chatRoomResourceId - }); - await using var transaction = await db.Database.BeginTransactionAsync(); try diff --git a/DysonNetwork.Messager/Chat/ChatService.cs b/DysonNetwork.Messager/Chat/ChatService.cs index 99f5145b..c28431c8 100644 --- a/DysonNetwork.Messager/Chat/ChatService.cs +++ b/DysonNetwork.Messager/Chat/ChatService.cs @@ -14,7 +14,6 @@ public partial class ChatService( AppDatabase db, ChatRoomService crs, FileService.FileServiceClient filesClient, - FileReferenceService.FileReferenceServiceClient fileRefs, IServiceScopeFactory scopeFactory, IRealtimeService realtime, ILogger logger, @@ -200,9 +199,6 @@ public partial class ChatService( db.ChatMessages.Add(message); await db.SaveChangesAsync(); - // Create file references if message has attachments - await CreateFileReferencesForMessageAsync(message); - // Copy the value to ensure the delivery is correct message.Sender = sender; message.ChatRoom = room; @@ -370,8 +366,11 @@ public partial class ChatService( } } - private List FilterAccountsForNotification(List members, SnChatMessage message, - SnChatMember sender) + private static List FilterAccountsForNotification( + List members, + SnChatMessage message, + SnChatMember sender + ) { var now = SystemClock.Instance.GetCurrentInstant(); @@ -392,51 +391,6 @@ public partial class ChatService( return accountsToNotify.Where(a => a.Id != sender.AccountId.ToString()).ToList(); } - private async Task CreateFileReferencesForMessageAsync(SnChatMessage message) - { - var files = message.Attachments.Distinct().ToList(); - if (files.Count == 0) return; - - var request = new CreateReferenceBatchRequest - { - Usage = ChatFileUsageIdentifier, - ResourceId = message.ResourceIdentifier, - }; - request.FilesId.AddRange(message.Attachments.Select(a => a.Id)); - await fileRefs.CreateReferenceBatchAsync(request); - } - - private async Task UpdateFileReferencesForMessageAsync(SnChatMessage message, List attachmentsId) - { - // Delete existing references for this message - await fileRefs.DeleteResourceReferencesAsync( - new DeleteResourceReferencesRequest { ResourceId = message.ResourceIdentifier } - ); - - // Create new references for each attachment - var createRequest = new CreateReferenceBatchRequest - { - Usage = ChatFileUsageIdentifier, - ResourceId = message.ResourceIdentifier, - }; - createRequest.FilesId.AddRange(attachmentsId); - await fileRefs.CreateReferenceBatchAsync(createRequest); - - // Update message attachments by getting files from database - var queryRequest = new GetFileBatchRequest(); - queryRequest.Ids.AddRange(attachmentsId); - var queryResult = await filesClient.GetFileBatchAsync(queryRequest); - message.Attachments = queryResult.Files.Select(SnCloudFileReferenceObject.FromProtoValue).ToList(); - } - - private async Task DeleteFileReferencesForMessageAsync(SnChatMessage message) - { - var messageResourceId = $"message:{message.Id}"; - await fileRefs.DeleteResourceReferencesAsync( - new DeleteResourceReferencesRequest { ResourceId = messageResourceId } - ); - } - /// /// This method will instant update the LastReadAt field for chat member, /// for better performance, using the flush buffer one instead @@ -709,9 +663,6 @@ public partial class ChatService( // Update do not override meta, replies to and forwarded to - if (attachmentsId is not null) - await UpdateFileReferencesForMessageAsync(message, attachmentsId); - // Mark as edited if content or attachments changed if (isContentChanged || isAttachmentsChanged) message.EditedAt = SystemClock.Instance.GetCurrentInstant(); @@ -774,9 +725,6 @@ public partial class ChatService( throw new InvalidOperationException("Only regular messages can be deleted."); } - // Remove all file references for this message - await DeleteFileReferencesForMessageAsync(message); - // Soft delete by setting DeletedAt timestamp message.DeletedAt = SystemClock.Instance.GetCurrentInstant(); message.UpdatedAt = message.DeletedAt.Value; diff --git a/DysonNetwork.Pass/Account/AccountCurrentController.cs b/DysonNetwork.Pass/Account/AccountCurrentController.cs index 9be46ce4..15e0ec1b 100644 --- a/DysonNetwork.Pass/Account/AccountCurrentController.cs +++ b/DysonNetwork.Pass/Account/AccountCurrentController.cs @@ -24,7 +24,6 @@ public class AccountCurrentController( AccountEventService events, AuthService auth, FileService.FileServiceClient files, - FileReferenceService.FileReferenceServiceClient fileRefs, Credit.SocialCreditService creditService ) : ControllerBase { @@ -122,36 +121,12 @@ public class AccountCurrentController( if (request.PictureId is not null) { var file = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId }); - if (profile.Picture is not null) - await fileRefs.DeleteResourceReferencesAsync( - new DeleteResourceReferencesRequest { ResourceId = profile.ResourceIdentifier } - ); - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - ResourceId = profile.ResourceIdentifier, - FileId = request.PictureId, - Usage = "profile.picture" - } - ); profile.Picture = SnCloudFileReferenceObject.FromProtoValue(file); } if (request.BackgroundId is not null) { var file = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId }); - if (profile.Background is not null) - await fileRefs.DeleteResourceReferencesAsync( - new DeleteResourceReferencesRequest { ResourceId = profile.ResourceIdentifier } - ); - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - ResourceId = profile.ResourceIdentifier, - FileId = request.BackgroundId, - Usage = "profile.background" - } - ); profile.Background = SnCloudFileReferenceObject.FromProtoValue(file); } diff --git a/DysonNetwork.Pass/Account/AccountService.cs b/DysonNetwork.Pass/Account/AccountService.cs index 97f7b235..e9868bf3 100644 --- a/DysonNetwork.Pass/Account/AccountService.cs +++ b/DysonNetwork.Pass/Account/AccountService.cs @@ -23,7 +23,6 @@ public class AccountService( AppDatabase db, MagicSpellService spells, FileService.FileServiceClient files, - FileReferenceService.FileReferenceServiceClient fileRefs, AccountUsernameService uname, AffiliationSpellService ars, EmailService mailer, @@ -229,28 +228,12 @@ public class AccountService( if (!string.IsNullOrEmpty(pictureId)) { var file = await files.GetFileAsync(new GetFileRequest { Id = pictureId }); - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - ResourceId = account.Profile.ResourceIdentifier, - FileId = pictureId, - Usage = "profile.picture" - } - ); account.Profile.Picture = SnCloudFileReferenceObject.FromProtoValue(file); } if (!string.IsNullOrEmpty(backgroundId)) { var file = await files.GetFileAsync(new GetFileRequest { Id = backgroundId }); - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - ResourceId = account.Profile.ResourceIdentifier, - FileId = backgroundId, - Usage = "profile.background" - } - ); account.Profile.Background = SnCloudFileReferenceObject.FromProtoValue(file); } diff --git a/DysonNetwork.Pass/Account/BotAccountReceiverGrpc.cs b/DysonNetwork.Pass/Account/BotAccountReceiverGrpc.cs index cbdf3cc7..cdf98afe 100644 --- a/DysonNetwork.Pass/Account/BotAccountReceiverGrpc.cs +++ b/DysonNetwork.Pass/Account/BotAccountReceiverGrpc.cs @@ -12,7 +12,6 @@ public class BotAccountReceiverGrpc( AppDatabase db, AccountService accounts, FileService.FileServiceClient files, - FileReferenceService.FileReferenceServiceClient fileRefs, AuthService authService ) : BotAccountReceiverService.BotAccountReceiverServiceBase @@ -53,36 +52,12 @@ public class BotAccountReceiverGrpc( if (request.PictureId is not null) { var file = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId }); - if (account.Profile.Picture is not null) - await fileRefs.DeleteResourceReferencesAsync( - new DeleteResourceReferencesRequest { ResourceId = account.Profile.ResourceIdentifier } - ); - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - ResourceId = account.Profile.ResourceIdentifier, - FileId = request.PictureId, - Usage = "profile.picture" - } - ); account.Profile.Picture = SnCloudFileReferenceObject.FromProtoValue(file); } if (request.BackgroundId is not null) { var file = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId }); - if (account.Profile.Background is not null) - await fileRefs.DeleteResourceReferencesAsync( - new DeleteResourceReferencesRequest { ResourceId = account.Profile.ResourceIdentifier } - ); - await fileRefs.CreateReferenceAsync( - new CreateReferenceRequest - { - ResourceId = account.Profile.ResourceIdentifier, - FileId = request.BackgroundId, - Usage = "profile.background" - } - ); account.Profile.Background = SnCloudFileReferenceObject.FromProtoValue(file); } diff --git a/DysonNetwork.Pass/Realm/RealmController.cs b/DysonNetwork.Pass/Realm/RealmController.cs index 4857a8df..24fcf15d 100644 --- a/DysonNetwork.Pass/Realm/RealmController.cs +++ b/DysonNetwork.Pass/Realm/RealmController.cs @@ -19,7 +19,6 @@ public class RealmController( AppDatabase db, RealmService rs, FileService.FileServiceClient files, - FileReferenceService.FileReferenceServiceClient fileRefs, ActionLogService als, RelationshipService rels, AccountEventService accountEvents @@ -414,28 +413,6 @@ public class RealmController( Request ); - var realmResourceId = $"realm:{realm.Id}"; - - if (realm.Picture is not null) - { - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = realm.Picture.Id, - Usage = "realm.picture", - ResourceId = realmResourceId - }); - } - - if (realm.Background is not null) - { - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = realm.Background.Id, - Usage = "realm.background", - ResourceId = realmResourceId - }); - } - return Ok(realm); } @@ -478,24 +455,7 @@ public class RealmController( var pictureResult = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId }); if (pictureResult is null) return BadRequest("Invalid picture id, unable to find the file on cloud."); - // Remove old references for the realm picture - if (realm.Picture is not null) - { - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { - ResourceId = realm.ResourceIdentifier - }); - } - realm.Picture = SnCloudFileReferenceObject.FromProtoValue(pictureResult); - - // Create a new reference - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = realm.Picture.Id, - Usage = "realm.picture", - ResourceId = realm.ResourceIdentifier - }); } if (request.BackgroundId is not null) @@ -503,24 +463,7 @@ public class RealmController( var backgroundResult = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId }); if (backgroundResult is null) return BadRequest("Invalid background id, unable to find the file on cloud."); - // Remove old references for the realm background - if (realm.Background is not null) - { - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { - ResourceId = realm.ResourceIdentifier - }); - } - realm.Background = SnCloudFileReferenceObject.FromProtoValue(backgroundResult); - - // Create a new reference - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = realm.Background.Id, - Usage = "realm.background", - ResourceId = realm.ResourceIdentifier - }); } db.Realms.Update(realm); @@ -733,13 +676,6 @@ public class RealmController( Request ); - // Delete all file references for this realm - var realmResourceId = $"realm:{realm.Id}"; - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { - ResourceId = realmResourceId - }); - return NoContent(); } } diff --git a/DysonNetwork.Shared/Proto/file.proto b/DysonNetwork.Shared/Proto/file.proto index c97f9775..dd486197 100644 --- a/DysonNetwork.Shared/Proto/file.proto +++ b/DysonNetwork.Shared/Proto/file.proto @@ -68,12 +68,6 @@ service FileService { // Delete a file reference rpc DeleteFile(DeleteFileRequest) returns (google.protobuf.Empty); - // Load files from references - rpc LoadFromReference(LoadFromReferenceRequest) returns (LoadFromReferenceResponse); - - // Check if a file is referenced by any resource - rpc IsReferenced(IsReferencedRequest) returns (IsReferencedResponse); - // Purge cache for a file rpc PurgeCache(PurgeCacheRequest) returns (google.protobuf.Empty); } @@ -116,196 +110,6 @@ message DeleteFileRequest { bool purge = 2; } -message LoadFromReferenceRequest { - repeated string reference_ids = 1; -} - -message LoadFromReferenceResponse { - repeated CloudFile files = 1; -} - -message GetReferenceCountRequest { - string file_id = 1; -} - -message GetReferenceCountResponse { - int32 count = 1; -} - -message IsReferencedRequest { - string file_id = 1; -} - -message IsReferencedResponse { - bool is_referenced = 1; -} - message PurgeCacheRequest { string file_id = 1; } - -// CloudFileReference represents a reference to a CloudFile with additional metadata -// about its usage in the system. -message CloudFileReference { - // Unique identifier for the reference - string id = 1; - - // Reference to the actual file - string file_id = 2; - - // The actual file data (optional, can be populated when needed) - CloudFile file = 3; - - // Description of how this file is being used - string usage = 4; - - // ID of the resource that this file is associated with - string resource_id = 5; - - // Optional expiration timestamp for the reference - google.protobuf.Timestamp expired_at = 6; -} - -// Request/Response messages for FileReferenceService -message CreateReferenceRequest { - string file_id = 1; - string usage = 2; - string resource_id = 3; - optional google.protobuf.Timestamp expired_at = 4; - optional google.protobuf.Duration duration = 5; // Alternative to expired_at -} - -message CreateReferenceBatchRequest { - repeated string files_id = 1; - string usage = 2; - string resource_id = 3; - optional google.protobuf.Timestamp expired_at = 4; - optional google.protobuf.Duration duration = 5; // Alternative to expired_at -} - -message CreateReferenceBatchResponse { - repeated CloudFileReference references = 1; -} - -message GetReferencesRequest { - string file_id = 1; -} - -message GetReferencesResponse { - repeated CloudFileReference references = 1; -} - -message GetResourceReferencesRequest { - string resource_id = 1; - string usage = 2; // Optional -} - -message GetResourceFilesRequest { - string resource_id = 1; - optional string usage = 2; -} - -message GetResourceFilesResponse { - repeated CloudFile files = 1; -} - -message DeleteResourceReferencesRequest { - string resource_id = 1; - optional string usage = 2; -} - -message DeleteResourceReferencesBatchRequest { - repeated string resource_ids = 1; - optional string usage = 2; -} - -message DeleteResourceReferencesResponse { - int32 deleted_count = 1; -} - -message DeleteReferenceRequest { - string reference_id = 1; -} - -message DeleteReferenceResponse { - bool success = 1; -} - -message UpdateResourceFilesRequest { - string resource_id = 1; - repeated string file_ids = 2; - string usage = 3; - google.protobuf.Timestamp expired_at = 4; - google.protobuf.Duration duration = 5; // Alternative to expired_at -} - -message UpdateResourceFilesResponse { - repeated CloudFileReference references = 1; -} - -message SetReferenceExpirationRequest { - string reference_id = 1; - google.protobuf.Timestamp expired_at = 2; - google.protobuf.Duration duration = 3; // Alternative to expired_at -} - -message SetReferenceExpirationResponse { - bool success = 1; -} - -message SetFileReferencesExpirationRequest { - string file_id = 1; - google.protobuf.Timestamp expired_at = 2; -} - -message SetFileReferencesExpirationResponse { - int32 updated_count = 1; -} - -message HasFileReferencesRequest { - string file_id = 1; -} - -message HasFileReferencesResponse { - bool has_references = 1; -} - -// Service for managing file references -service FileReferenceService { - // Creates a new reference to a file for a specific resource - rpc CreateReference(CreateReferenceRequest) returns (CloudFileReference); - rpc CreateReferenceBatch(CreateReferenceBatchRequest) returns (CreateReferenceBatchResponse); - - // Gets all references to a file - rpc GetReferences(GetReferencesRequest) returns (GetReferencesResponse); - - // Gets the number of references to a file - rpc GetReferenceCount(GetReferenceCountRequest) returns (GetReferenceCountResponse); - - // Gets all references for a specific resource and optional usage - rpc GetResourceReferences(GetResourceReferencesRequest) returns (GetReferencesResponse); - - // Gets all files referenced by a resource with optional usage filter - rpc GetResourceFiles(GetResourceFilesRequest) returns (GetResourceFilesResponse); - - // Deletes references for a specific resource and optional usage - rpc DeleteResourceReferences(DeleteResourceReferencesRequest) returns (DeleteResourceReferencesResponse); - - // Deletes references for multiple specific resources and optional usage - rpc DeleteResourceReferencesBatch(DeleteResourceReferencesBatchRequest) returns (DeleteResourceReferencesResponse); - - // Deletes a specific file reference - rpc DeleteReference(DeleteReferenceRequest) returns (DeleteReferenceResponse); - - // Updates the files referenced by a resource - rpc UpdateResourceFiles(UpdateResourceFilesRequest) returns (UpdateResourceFilesResponse); - - // Updates the expiration time for a file reference - rpc SetReferenceExpiration(SetReferenceExpirationRequest) returns (SetReferenceExpirationResponse); - - // Updates the expiration time for all references to a file - rpc SetFileReferencesExpiration(SetFileReferencesExpirationRequest) returns (SetFileReferencesExpirationResponse); - - // Checks if a file has any references - rpc HasFileReferences(HasFileReferencesRequest) returns (HasFileReferencesResponse); -} diff --git a/DysonNetwork.Shared/Registry/ServiceInjectionHelper.cs b/DysonNetwork.Shared/Registry/ServiceInjectionHelper.cs index 329245a3..06114757 100644 --- a/DysonNetwork.Shared/Registry/ServiceInjectionHelper.cs +++ b/DysonNetwork.Shared/Registry/ServiceInjectionHelper.cs @@ -69,10 +69,6 @@ public static class ServiceInjectionHelper "https://_grpc.drive", "FileService"); - services.AddGrpcClientWithSharedChannel( - "https://_grpc.drive", - "FileReferenceService"); - return services; } diff --git a/DysonNetwork.Sphere/Sticker/StickerController.cs b/DysonNetwork.Sphere/Sticker/StickerController.cs index 2e0300c2..225c4f6d 100644 --- a/DysonNetwork.Sphere/Sticker/StickerController.cs +++ b/DysonNetwork.Sphere/Sticker/StickerController.cs @@ -15,8 +15,7 @@ public class StickerController( AppDatabase db, StickerService st, Publisher.PublisherService ps, - FileService.FileServiceClient files, - FileReferenceService.FileReferenceServiceClient fileRefs + FileService.FileServiceClient files ) : ControllerBase { private async Task _CheckStickerPackPermissions( @@ -161,16 +160,6 @@ public class StickerController( db.StickerPacks.Add(pack); await db.SaveChangesAsync(); - if (pack.Icon is not null) - { - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = pack.Icon.Id, - Usage = StickerService.StickerPackUsageIdentifier, - ResourceId = pack.ResourceIdentifier - }); - } - return Ok(pack); } @@ -207,24 +196,7 @@ public class StickerController( if (file is null) return BadRequest("Icon not found."); - if (file.Id != pack.Icon?.Id) - { - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { ResourceId = pack.ResourceIdentifier, Usage = StickerService.StickerPackUsageIdentifier }); - - pack.Icon = SnCloudFileReferenceObject.FromProtoValue(file); - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = pack.Icon.Id, - Usage = StickerService.StickerPackUsageIdentifier, - ResourceId = pack.ResourceIdentifier - }); - } - else - { - // Still update the column in case user want to sync the changes of the file meta - pack.Icon = SnCloudFileReferenceObject.FromProtoValue(file); - } + pack.Icon = SnCloudFileReferenceObject.FromProtoValue(file); } db.StickerPacks.Update(pack); diff --git a/DysonNetwork.Sphere/Sticker/StickerService.cs b/DysonNetwork.Sphere/Sticker/StickerService.cs index 5038c43f..b269b22f 100644 --- a/DysonNetwork.Sphere/Sticker/StickerService.cs +++ b/DysonNetwork.Sphere/Sticker/StickerService.cs @@ -7,13 +7,9 @@ namespace DysonNetwork.Sphere.Sticker; public class StickerService( AppDatabase db, - FileReferenceService.FileReferenceServiceClient fileRefs, ICacheService cache ) { - public const string StickerFileUsageIdentifier = "sticker"; - public const string StickerPackUsageIdentifier = "sticker.pack"; - private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(15); public async Task CreateStickerAsync(SnSticker sticker) @@ -23,34 +19,14 @@ public class StickerService( db.Stickers.Add(sticker); await db.SaveChangesAsync(); - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = sticker.Image.Id, - Usage = StickerFileUsageIdentifier, - ResourceId = sticker.ResourceIdentifier - }); - return sticker; } public async Task UpdateStickerAsync(SnSticker sticker, SnCloudFileReferenceObject? newImage) { if (newImage is not null) - { - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { ResourceId = sticker.ResourceIdentifier }); - sticker.Image = newImage; - // Create new reference - await fileRefs.CreateReferenceAsync(new CreateReferenceRequest - { - FileId = newImage.Id, - Usage = StickerFileUsageIdentifier, - ResourceId = sticker.ResourceIdentifier - }); - } - db.Stickers.Update(sticker); await db.SaveChangesAsync(); @@ -62,12 +38,6 @@ public class StickerService( public async Task DeleteStickerAsync(SnSticker sticker) { - var stickerResourceId = $"sticker:{sticker.Id}"; - - // Delete all file references for this sticker - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { ResourceId = stickerResourceId }); - db.Stickers.Remove(sticker); await db.SaveChangesAsync(); @@ -81,17 +51,6 @@ public class StickerService( .Where(s => s.PackId == pack.Id) .ToListAsync(); - var images = stickers.Select(s => s.Image).ToList(); - - // Delete all file references for each sticker in the pack - foreach (var stickerResourceId in stickers.Select(sticker => $"sticker:{sticker.Id}")) - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { ResourceId = stickerResourceId }); - - // Delete any references for the pack itself - await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest - { ResourceId = pack.ResourceIdentifier }); - db.Stickers.RemoveRange(stickers); db.StickerPacks.Remove(pack); await db.SaveChangesAsync();