using FrostFS.SDK.ClientV2; using FrostFS.SDK.ClientV2.Interfaces; using FrostFS.SDK.ClientV2.Mappers.GRPC; using FrostFS.SDK.ModelsV2; namespace FrostFS.SDK.Service; // TODO: Проверять ответы Grpc public class FrostFsService { private readonly IFrostFSClient _client; public FrostFsService(IFrostFSClient client) { _client = client; } public async Task ListContainersAsync() { var listContainersResponse = await _client.ListContainersAsync(); return listContainersResponse.Body.ContainerIds.Select( cid => ContainerId.FromHash(cid.Value.ToByteArray()) ).ToArray(); } public async Task CreateContainerAsync(ModelsV2.Container container) { var createContainerResponse = await _client.CreateContainerAsync(container.ToGrpcMessage()); return ContainerId.FromHash(createContainerResponse.Body.ContainerId.Value.ToByteArray()); } public async Task GetContainerAsync(ContainerId containerId) { var getContainerResponse = await _client.GetContainerAsync(containerId.ToGrpcMessage()); return getContainerResponse.Body.Container.ToModel(); } public async Task DeleteContainerAsync(ContainerId containerId) { var deleteContainerResponse = await _client.DeleteContainerAsync(containerId.ToGrpcMessage()); } public async Task GetObjectHeadAsync(ContainerId containerId, ObjectId objectId) { var getObjectHeadResponse = await _client.GetObjectHeadAsync( containerId.ToGrpcMessage(), objectId.ToGrpcMessage() ); return getObjectHeadResponse.Body.Header.Header.ToModel(); } public async Task GetObjectAsync(ContainerId containerId, ObjectId objectId) { var obj = await _client.GetObjectAsync( containerId.ToGrpcMessage(), objectId.ToGrpcMessage() ); return obj.ToModel(); } public async Task PutObjectAsync(ObjectHeader header, Stream payload) { var putObjectResponse = await _client.PutObjectAsync(header.ToGrpcMessage(), payload); return ObjectId.FromHash(putObjectResponse.Body.ObjectId.Value.ToByteArray()); } public async Task PutObjectAsync(ObjectHeader header, byte[] payload) { var putObjectResponse = await _client.PutObjectAsync(header.ToGrpcMessage(), new MemoryStream(payload)); return ObjectId.FromHash(putObjectResponse.Body.ObjectId.Value.ToByteArray()); } public async Task DeleteObjectAsync(ContainerId containerId, ObjectId objectId) { var deleteObjectResponse = await _client.DeleteObjectAsync( containerId.ToGrpcMessage(), objectId.ToGrpcMessage() ); } }