🗑️ Remove the unused reference system
This commit is contained in:
@@ -8,7 +8,6 @@ namespace DysonNetwork.Develop.Identity;
|
|||||||
|
|
||||||
public class CustomAppService(
|
public class CustomAppService(
|
||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
|
||||||
FileService.FileServiceClient files
|
FileService.FileServiceClient files
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -46,16 +45,6 @@ public class CustomAppService(
|
|||||||
if (picture is null)
|
if (picture is null)
|
||||||
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
|
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
|
||||||
app.Picture = SnCloudFileReferenceObject.FromProtoValue(picture);
|
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)
|
if (request.BackgroundId is not null)
|
||||||
{
|
{
|
||||||
@@ -65,16 +54,6 @@ public class CustomAppService(
|
|||||||
if (background is null)
|
if (background is null)
|
||||||
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
|
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
|
||||||
app.Background = SnCloudFileReferenceObject.FromProtoValue(background);
|
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);
|
db.CustomApps.Add(app);
|
||||||
@@ -209,16 +188,6 @@ public class CustomAppService(
|
|||||||
if (picture is null)
|
if (picture is null)
|
||||||
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
|
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
|
||||||
app.Picture = SnCloudFileReferenceObject.FromProtoValue(picture);
|
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)
|
if (request.BackgroundId is not null)
|
||||||
{
|
{
|
||||||
@@ -228,16 +197,6 @@ public class CustomAppService(
|
|||||||
if (background is null)
|
if (background is null)
|
||||||
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
|
throw new InvalidOperationException("Invalid picture id, unable to find the file on cloud.");
|
||||||
app.Background = SnCloudFileReferenceObject.FromProtoValue(background);
|
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);
|
db.Update(app);
|
||||||
@@ -257,12 +216,6 @@ public class CustomAppService(
|
|||||||
db.CustomApps.Remove(app);
|
db.CustomApps.Remove(app);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest
|
|
||||||
{
|
|
||||||
ResourceId = app.ResourceIdentifier
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,27 +41,6 @@ namespace DysonNetwork.Drive.Storage
|
|||||||
return new Empty();
|
return new Empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<LoadFromReferenceResponse> 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<IsReferencedResponse> IsReferenced(IsReferencedRequest request,
|
|
||||||
ServerCallContext context)
|
|
||||||
{
|
|
||||||
var isReferenced = await fileService.IsReferencedAsync(request.FileId);
|
|
||||||
return new IsReferencedResponse { IsReferenced = isReferenced };
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<Empty> PurgeCache(PurgeCacheRequest request, ServerCallContext context)
|
public override async Task<Empty> PurgeCache(PurgeCacheRequest request, ServerCallContext context)
|
||||||
{
|
{
|
||||||
await fileService._PurgeCacheAsync(request.FileId);
|
await fileService._PurgeCacheAsync(request.FileId);
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ public class ChatRoomController(
|
|||||||
RemoteRealmService rs,
|
RemoteRealmService rs,
|
||||||
AccountService.AccountServiceClient accounts,
|
AccountService.AccountServiceClient accounts,
|
||||||
FileService.FileServiceClient files,
|
FileService.FileServiceClient files,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
|
||||||
ActionLogService.ActionLogServiceClient als,
|
ActionLogService.ActionLogServiceClient als,
|
||||||
RingService.RingServiceClient pusher,
|
RingService.RingServiceClient pusher,
|
||||||
RemoteAccountService remoteAccountsHelper
|
RemoteAccountService remoteAccountsHelper
|
||||||
@@ -220,13 +219,6 @@ public class ChatRoomController(
|
|||||||
var fileResponse = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId });
|
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.");
|
if (fileResponse == null) return BadRequest("Invalid picture id, unable to find the file on cloud.");
|
||||||
chatRoom.Picture = SnCloudFileReferenceObject.FromProtoValue(fileResponse);
|
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)
|
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 });
|
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.");
|
if (fileResponse == null) return BadRequest("Invalid background id, unable to find the file on cloud.");
|
||||||
chatRoom.Background = SnCloudFileReferenceObject.FromProtoValue(fileResponse);
|
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)
|
catch (RpcException ex) when (ex.StatusCode == Grpc.Core.StatusCode.NotFound)
|
||||||
{
|
{
|
||||||
@@ -258,28 +243,6 @@ public class ChatRoomController(
|
|||||||
db.ChatRooms.Add(chatRoom);
|
db.ChatRooms.Add(chatRoom);
|
||||||
await db.SaveChangesAsync();
|
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
|
_ = als.CreateActionLogAsync(new CreateActionLogRequest
|
||||||
{
|
{
|
||||||
Action = "chatrooms.create",
|
Action = "chatrooms.create",
|
||||||
@@ -329,21 +292,6 @@ public class ChatRoomController(
|
|||||||
var fileResponse = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId });
|
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.");
|
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);
|
chatRoom.Picture = SnCloudFileReferenceObject.FromProtoValue(fileResponse);
|
||||||
}
|
}
|
||||||
catch (RpcException ex) when (ex.StatusCode == Grpc.Core.StatusCode.NotFound)
|
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 });
|
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.");
|
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);
|
chatRoom.Background = SnCloudFileReferenceObject.FromProtoValue(fileResponse);
|
||||||
}
|
}
|
||||||
catch (RpcException ex) when (ex.StatusCode == Grpc.Core.StatusCode.NotFound)
|
catch (RpcException ex) when (ex.StatusCode == Grpc.Core.StatusCode.NotFound)
|
||||||
@@ -427,14 +360,6 @@ public class ChatRoomController(
|
|||||||
else if (chatRoom.AccountId != accountId)
|
else if (chatRoom.AccountId != accountId)
|
||||||
return StatusCode(403, "You need be the owner to update the chat.");
|
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();
|
await using var transaction = await db.Database.BeginTransactionAsync();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ public partial class ChatService(
|
|||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
ChatRoomService crs,
|
ChatRoomService crs,
|
||||||
FileService.FileServiceClient filesClient,
|
FileService.FileServiceClient filesClient,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
|
||||||
IServiceScopeFactory scopeFactory,
|
IServiceScopeFactory scopeFactory,
|
||||||
IRealtimeService realtime,
|
IRealtimeService realtime,
|
||||||
ILogger<ChatService> logger,
|
ILogger<ChatService> logger,
|
||||||
@@ -200,9 +199,6 @@ public partial class ChatService(
|
|||||||
db.ChatMessages.Add(message);
|
db.ChatMessages.Add(message);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
// Create file references if message has attachments
|
|
||||||
await CreateFileReferencesForMessageAsync(message);
|
|
||||||
|
|
||||||
// Copy the value to ensure the delivery is correct
|
// Copy the value to ensure the delivery is correct
|
||||||
message.Sender = sender;
|
message.Sender = sender;
|
||||||
message.ChatRoom = room;
|
message.ChatRoom = room;
|
||||||
@@ -370,8 +366,11 @@ public partial class ChatService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Account> FilterAccountsForNotification(List<SnChatMember> members, SnChatMessage message,
|
private static List<Account> FilterAccountsForNotification(
|
||||||
SnChatMember sender)
|
List<SnChatMember> members,
|
||||||
|
SnChatMessage message,
|
||||||
|
SnChatMember sender
|
||||||
|
)
|
||||||
{
|
{
|
||||||
var now = SystemClock.Instance.GetCurrentInstant();
|
var now = SystemClock.Instance.GetCurrentInstant();
|
||||||
|
|
||||||
@@ -392,51 +391,6 @@ public partial class ChatService(
|
|||||||
return accountsToNotify.Where(a => a.Id != sender.AccountId.ToString()).ToList();
|
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<string> 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 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method will instant update the LastReadAt field for chat member,
|
/// This method will instant update the LastReadAt field for chat member,
|
||||||
/// for better performance, using the flush buffer one instead
|
/// 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
|
// 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
|
// Mark as edited if content or attachments changed
|
||||||
if (isContentChanged || isAttachmentsChanged)
|
if (isContentChanged || isAttachmentsChanged)
|
||||||
message.EditedAt = SystemClock.Instance.GetCurrentInstant();
|
message.EditedAt = SystemClock.Instance.GetCurrentInstant();
|
||||||
@@ -774,9 +725,6 @@ public partial class ChatService(
|
|||||||
throw new InvalidOperationException("Only regular messages can be deleted.");
|
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
|
// Soft delete by setting DeletedAt timestamp
|
||||||
message.DeletedAt = SystemClock.Instance.GetCurrentInstant();
|
message.DeletedAt = SystemClock.Instance.GetCurrentInstant();
|
||||||
message.UpdatedAt = message.DeletedAt.Value;
|
message.UpdatedAt = message.DeletedAt.Value;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ public class AccountCurrentController(
|
|||||||
AccountEventService events,
|
AccountEventService events,
|
||||||
AuthService auth,
|
AuthService auth,
|
||||||
FileService.FileServiceClient files,
|
FileService.FileServiceClient files,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
|
||||||
Credit.SocialCreditService creditService
|
Credit.SocialCreditService creditService
|
||||||
) : ControllerBase
|
) : ControllerBase
|
||||||
{
|
{
|
||||||
@@ -122,36 +121,12 @@ public class AccountCurrentController(
|
|||||||
if (request.PictureId is not null)
|
if (request.PictureId is not null)
|
||||||
{
|
{
|
||||||
var file = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId });
|
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);
|
profile.Picture = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.BackgroundId is not null)
|
if (request.BackgroundId is not null)
|
||||||
{
|
{
|
||||||
var file = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId });
|
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);
|
profile.Background = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ public class AccountService(
|
|||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
MagicSpellService spells,
|
MagicSpellService spells,
|
||||||
FileService.FileServiceClient files,
|
FileService.FileServiceClient files,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
|
||||||
AccountUsernameService uname,
|
AccountUsernameService uname,
|
||||||
AffiliationSpellService ars,
|
AffiliationSpellService ars,
|
||||||
EmailService mailer,
|
EmailService mailer,
|
||||||
@@ -229,28 +228,12 @@ public class AccountService(
|
|||||||
if (!string.IsNullOrEmpty(pictureId))
|
if (!string.IsNullOrEmpty(pictureId))
|
||||||
{
|
{
|
||||||
var file = await files.GetFileAsync(new GetFileRequest { Id = 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);
|
account.Profile.Picture = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(backgroundId))
|
if (!string.IsNullOrEmpty(backgroundId))
|
||||||
{
|
{
|
||||||
var file = await files.GetFileAsync(new GetFileRequest { Id = 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);
|
account.Profile.Background = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ public class BotAccountReceiverGrpc(
|
|||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
AccountService accounts,
|
AccountService accounts,
|
||||||
FileService.FileServiceClient files,
|
FileService.FileServiceClient files,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
|
||||||
AuthService authService
|
AuthService authService
|
||||||
)
|
)
|
||||||
: BotAccountReceiverService.BotAccountReceiverServiceBase
|
: BotAccountReceiverService.BotAccountReceiverServiceBase
|
||||||
@@ -53,36 +52,12 @@ public class BotAccountReceiverGrpc(
|
|||||||
if (request.PictureId is not null)
|
if (request.PictureId is not null)
|
||||||
{
|
{
|
||||||
var file = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId });
|
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);
|
account.Profile.Picture = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.BackgroundId is not null)
|
if (request.BackgroundId is not null)
|
||||||
{
|
{
|
||||||
var file = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId });
|
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);
|
account.Profile.Background = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ public class RealmController(
|
|||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
RealmService rs,
|
RealmService rs,
|
||||||
FileService.FileServiceClient files,
|
FileService.FileServiceClient files,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
|
||||||
ActionLogService als,
|
ActionLogService als,
|
||||||
RelationshipService rels,
|
RelationshipService rels,
|
||||||
AccountEventService accountEvents
|
AccountEventService accountEvents
|
||||||
@@ -414,28 +413,6 @@ public class RealmController(
|
|||||||
Request
|
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);
|
return Ok(realm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,24 +455,7 @@ public class RealmController(
|
|||||||
var pictureResult = await files.GetFileAsync(new GetFileRequest { Id = request.PictureId });
|
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.");
|
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);
|
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)
|
if (request.BackgroundId is not null)
|
||||||
@@ -503,24 +463,7 @@ public class RealmController(
|
|||||||
var backgroundResult = await files.GetFileAsync(new GetFileRequest { Id = request.BackgroundId });
|
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.");
|
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);
|
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);
|
db.Realms.Update(realm);
|
||||||
@@ -733,13 +676,6 @@ public class RealmController(
|
|||||||
Request
|
Request
|
||||||
);
|
);
|
||||||
|
|
||||||
// Delete all file references for this realm
|
|
||||||
var realmResourceId = $"realm:{realm.Id}";
|
|
||||||
await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest
|
|
||||||
{
|
|
||||||
ResourceId = realmResourceId
|
|
||||||
});
|
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,12 +68,6 @@ service FileService {
|
|||||||
// Delete a file reference
|
// Delete a file reference
|
||||||
rpc DeleteFile(DeleteFileRequest) returns (google.protobuf.Empty);
|
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
|
// Purge cache for a file
|
||||||
rpc PurgeCache(PurgeCacheRequest) returns (google.protobuf.Empty);
|
rpc PurgeCache(PurgeCacheRequest) returns (google.protobuf.Empty);
|
||||||
}
|
}
|
||||||
@@ -116,196 +110,6 @@ message DeleteFileRequest {
|
|||||||
bool purge = 2;
|
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 {
|
message PurgeCacheRequest {
|
||||||
string file_id = 1;
|
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);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -69,10 +69,6 @@ public static class ServiceInjectionHelper
|
|||||||
"https://_grpc.drive",
|
"https://_grpc.drive",
|
||||||
"FileService");
|
"FileService");
|
||||||
|
|
||||||
services.AddGrpcClientWithSharedChannel<FileReferenceService.FileReferenceServiceClient>(
|
|
||||||
"https://_grpc.drive",
|
|
||||||
"FileReferenceService");
|
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ public class StickerController(
|
|||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
StickerService st,
|
StickerService st,
|
||||||
Publisher.PublisherService ps,
|
Publisher.PublisherService ps,
|
||||||
FileService.FileServiceClient files,
|
FileService.FileServiceClient files
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs
|
|
||||||
) : ControllerBase
|
) : ControllerBase
|
||||||
{
|
{
|
||||||
private async Task<IActionResult> _CheckStickerPackPermissions(
|
private async Task<IActionResult> _CheckStickerPackPermissions(
|
||||||
@@ -161,16 +160,6 @@ public class StickerController(
|
|||||||
db.StickerPacks.Add(pack);
|
db.StickerPacks.Add(pack);
|
||||||
await db.SaveChangesAsync();
|
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);
|
return Ok(pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,24 +196,7 @@ public class StickerController(
|
|||||||
if (file is null)
|
if (file is null)
|
||||||
return BadRequest("Icon not found.");
|
return BadRequest("Icon not found.");
|
||||||
|
|
||||||
if (file.Id != pack.Icon?.Id)
|
pack.Icon = SnCloudFileReferenceObject.FromProtoValue(file);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
db.StickerPacks.Update(pack);
|
db.StickerPacks.Update(pack);
|
||||||
|
|||||||
@@ -7,13 +7,9 @@ namespace DysonNetwork.Sphere.Sticker;
|
|||||||
|
|
||||||
public class StickerService(
|
public class StickerService(
|
||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
|
||||||
ICacheService cache
|
ICacheService cache
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
public const string StickerFileUsageIdentifier = "sticker";
|
|
||||||
public const string StickerPackUsageIdentifier = "sticker.pack";
|
|
||||||
|
|
||||||
private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(15);
|
private static readonly TimeSpan CacheDuration = TimeSpan.FromMinutes(15);
|
||||||
|
|
||||||
public async Task<SnSticker> CreateStickerAsync(SnSticker sticker)
|
public async Task<SnSticker> CreateStickerAsync(SnSticker sticker)
|
||||||
@@ -23,34 +19,14 @@ public class StickerService(
|
|||||||
db.Stickers.Add(sticker);
|
db.Stickers.Add(sticker);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
await fileRefs.CreateReferenceAsync(new CreateReferenceRequest
|
|
||||||
{
|
|
||||||
FileId = sticker.Image.Id,
|
|
||||||
Usage = StickerFileUsageIdentifier,
|
|
||||||
ResourceId = sticker.ResourceIdentifier
|
|
||||||
});
|
|
||||||
|
|
||||||
return sticker;
|
return sticker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<SnSticker> UpdateStickerAsync(SnSticker sticker, SnCloudFileReferenceObject? newImage)
|
public async Task<SnSticker> UpdateStickerAsync(SnSticker sticker, SnCloudFileReferenceObject? newImage)
|
||||||
{
|
{
|
||||||
if (newImage is not null)
|
if (newImage is not null)
|
||||||
{
|
|
||||||
await fileRefs.DeleteResourceReferencesAsync(new DeleteResourceReferencesRequest
|
|
||||||
{ ResourceId = sticker.ResourceIdentifier });
|
|
||||||
|
|
||||||
sticker.Image = newImage;
|
sticker.Image = newImage;
|
||||||
|
|
||||||
// Create new reference
|
|
||||||
await fileRefs.CreateReferenceAsync(new CreateReferenceRequest
|
|
||||||
{
|
|
||||||
FileId = newImage.Id,
|
|
||||||
Usage = StickerFileUsageIdentifier,
|
|
||||||
ResourceId = sticker.ResourceIdentifier
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
db.Stickers.Update(sticker);
|
db.Stickers.Update(sticker);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -62,12 +38,6 @@ public class StickerService(
|
|||||||
|
|
||||||
public async Task DeleteStickerAsync(SnSticker sticker)
|
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);
|
db.Stickers.Remove(sticker);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -81,17 +51,6 @@ public class StickerService(
|
|||||||
.Where(s => s.PackId == pack.Id)
|
.Where(s => s.PackId == pack.Id)
|
||||||
.ToListAsync();
|
.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.Stickers.RemoveRange(stickers);
|
||||||
db.StickerPacks.Remove(pack);
|
db.StickerPacks.Remove(pack);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|||||||
Reference in New Issue
Block a user