adds AddChunkAsync to image api
This commit is contained in:
parent
171aeb6e5e
commit
7074ebf709
@ -1,3 +1,4 @@
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Piwigo.Client.Contract;
|
||||
|
||||
@ -14,6 +15,24 @@ public class ImageApiTests : ApiTestsBase
|
||||
_imageApi = new ImageApi(Context, new NullLogger<ImageApi>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AddChunk_should_post_base64_encoded_data()
|
||||
{
|
||||
SetOkResult();
|
||||
|
||||
var bytes = Encoding.UTF8.GetBytes("PiwigoTestString");
|
||||
var expectedBase64 = Convert.ToBase64String(bytes);
|
||||
|
||||
await _imageApi.AddChunkAsync(bytes, "origSum", 0);
|
||||
|
||||
CorrectMethodShouldGetCalled("pwg.images.addChunk");
|
||||
|
||||
CorrectParamShouldGetSent("data", expectedBase64);
|
||||
CorrectParamShouldGetSent("original_sum", "origSum");
|
||||
CorrectParamShouldGetSent("type", "file");
|
||||
CorrectParamShouldGetSent("position", "0");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetImages_should_return_expected_images()
|
||||
{
|
||||
|
@ -4,6 +4,8 @@ namespace Piwigo.Client;
|
||||
|
||||
public interface IImageApi
|
||||
{
|
||||
Task AddChunkAsync(byte[] data, string originalSum, int position, CancellationToken cancellationToken = default);
|
||||
|
||||
Task<PagedImages> GetImages(int albumId, bool recursive, PagingInfo page, ImageFilter filter, ImageOrder order = ImageOrder.Name,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
@ -15,6 +15,22 @@ public class ImageApi : IImageApi
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public async Task AddChunkAsync(byte[] data, string originalSum, int position, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var base64Data = Convert.ToBase64String(data);
|
||||
|
||||
var formParams = new Dictionary<string, string>
|
||||
{
|
||||
{ "data", base64Data },
|
||||
{ "original_sum", originalSum },
|
||||
// type = file is required for compatibility reasons.
|
||||
// There is no other value allowed
|
||||
{ "type", "file" },
|
||||
{ "position", position.ToString() }
|
||||
};
|
||||
await _context.PostAsync<PiwigoResponse>(_logger, "pwg.images.addChunk", formParams, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<PagedImages> GetImages(int albumId, bool recursive, PagingInfo page, ImageFilter filter, ImageOrder order = ImageOrder.Name,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user