From 002734f6922e8cb11405d584df74b3f9da0fdb06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Sat, 22 Oct 2022 20:36:20 +0200 Subject: [PATCH] adds check upload --- .../Piwigo.Client.Tests/ImageApiTests.cs | 16 +++++++++++ .../Piwigo.Client/Contract/CheckUpload.cs | 12 ++++++++ PiwigoDotnet/Piwigo.Client/IImageApi.cs | 28 +++++++++++++++++++ PiwigoDotnet/Piwigo.Client/ImageApi.cs | 6 ++++ 4 files changed, 62 insertions(+) create mode 100644 PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs diff --git a/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.cs b/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.cs index 135a09f..63e7ddb 100644 --- a/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.cs +++ b/PiwigoDotnet/Piwigo.Client.Tests/ImageApiTests.cs @@ -15,6 +15,22 @@ public class ImageApiTests : ApiTestsBase _imageApi = new ImageApi(Context, new NullLogger()); } + [Test] + public async Task ReadyForUpload_should_return_correct_value() + { + SetJsonResult(@"{stat: ""ok"", + result: { + message: null, + ready_for_upload: true + }}"); + + var isReady = await _imageApi.ReadyForUploadAsync(); + + CorrectMethodShouldGetCalled("pwg.images.checkUpload"); + + isReady.Should().BeTrue(); + } + [Test] public async Task AddChunk_should_post_base64_encoded_data() { diff --git a/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs b/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs new file mode 100644 index 0000000..f3f7ed7 --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Piwigo.Client.Contract; + +public class CheckUpload +{ + [JsonProperty("message")] + public string? Message { get; init; } + + [JsonProperty("ready_for_upload")] + public bool IsReady { get; init; } +} \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client/IImageApi.cs b/PiwigoDotnet/Piwigo.Client/IImageApi.cs index b1bdb4e..7393a52 100644 --- a/PiwigoDotnet/Piwigo.Client/IImageApi.cs +++ b/PiwigoDotnet/Piwigo.Client/IImageApi.cs @@ -6,6 +6,34 @@ public interface IImageApi { Task AddChunkAsync(byte[] data, string originalSum, int position, CancellationToken cancellationToken = default); + Task ReadyForUploadAsync(CancellationToken cancellationToken = default); + Task GetImages(int albumId, bool recursive, PagingInfo page, ImageFilter filter, ImageOrder order = ImageOrder.Name, CancellationToken cancellationToken = default); + + /* +add +addComment +addFile +addSimple +checkFiles +delete +deleteOrphans +emptyLounge +exist +-> formats + delete + searchImage +getInfo +rate +search +setInfo +setMd5sum +setPrivacyLevel +setRank +syncMetadata +upload +uploadAsync +uploadCompleted +*/ } \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client/ImageApi.cs b/PiwigoDotnet/Piwigo.Client/ImageApi.cs index 2f026db..fb19b8e 100644 --- a/PiwigoDotnet/Piwigo.Client/ImageApi.cs +++ b/PiwigoDotnet/Piwigo.Client/ImageApi.cs @@ -31,6 +31,12 @@ public class ImageApi : IImageApi await _context.PostAsync(_logger, "pwg.images.addChunk", formParams, cancellationToken); } + public async Task ReadyForUploadAsync(CancellationToken cancellationToken = default) + { + var response = await _context.PostAsync>(_logger, "pwg.images.checkUpload", new Dictionary(), cancellationToken); + return response.Result.IsReady; + } + public async Task GetImages(int albumId, bool recursive, PagingInfo page, ImageFilter filter, ImageOrder order = ImageOrder.Name, CancellationToken cancellationToken = default) {