diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2022-10-01 21:55:07 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2022-10-01 21:55:07 +0200 |
commit | f542481df58f3222143bc260feb34b5cf537d8e0 (patch) | |
tree | 31cd86e358bc70e6d83955fdcc0d8e05fc32c325 /plugins/shotwell-publishing/PhotosPublisher.vala | |
parent | 0b99aa7b114b6c8eb0d55742c4be2f3a73f44e39 (diff) | |
parent | bb0e1e40d2de6b093b564f4f2cd0c44aa32380b8 (diff) |
Update upstream source from tag 'upstream/0.30.17'
Update to upstream version '0.30.17'
with Debian dir 3a9f978d21f3777edc044a3c6b84923dd9b60a25
Diffstat (limited to 'plugins/shotwell-publishing/PhotosPublisher.vala')
-rw-r--r-- | plugins/shotwell-publishing/PhotosPublisher.vala | 81 |
1 files changed, 42 insertions, 39 deletions
diff --git a/plugins/shotwell-publishing/PhotosPublisher.vala b/plugins/shotwell-publishing/PhotosPublisher.vala index e1127ac..879f5fc 100644 --- a/plugins/shotwell-publishing/PhotosPublisher.vala +++ b/plugins/shotwell-publishing/PhotosPublisher.vala @@ -128,41 +128,28 @@ private class MediaCreationTransaction : Publishing.RESTSupport.GooglePublisher. } public override void execute () throws Spit.Publishing.PublishingError { - for (var h = 0; h * MAX_BATCH_SIZE < this.upload_tokens.length; h++) { - var offset = h * MAX_BATCH_SIZE; - var difference = this.upload_tokens.length - offset; - int end; - - if (difference > MAX_BATCH_SIZE) { - end = offset + MAX_BATCH_SIZE; - } - else { - end = offset + difference; - } - - var builder = new Json.Builder(); + var builder = new Json.Builder(); + builder.begin_object(); + builder.set_member_name("albumId"); + builder.add_string_value(this.album_id); + builder.set_member_name("newMediaItems"); + builder.begin_array(); + for (var i = 0; i < this.upload_tokens.length; i++) { builder.begin_object(); - builder.set_member_name("albumId"); - builder.add_string_value(this.album_id); - builder.set_member_name("newMediaItems"); - builder.begin_array(); - for (var i = offset; i < end; i++) { - builder.begin_object(); - builder.set_member_name("description"); - builder.add_string_value(this.titles[i]); - builder.set_member_name("simpleMediaItem"); - builder.begin_object(); - builder.set_member_name("uploadToken"); - builder.add_string_value(this.upload_tokens[i]); - builder.end_object(); - builder.end_object(); - } - builder.end_array(); + builder.set_member_name("description"); + builder.add_string_value(this.titles[i]); + builder.set_member_name("simpleMediaItem"); + builder.begin_object(); + builder.set_member_name("uploadToken"); + builder.add_string_value(this.upload_tokens[i]); + builder.end_object(); builder.end_object(); - set_custom_payload(Json.to_string (builder.get_root (), false), "application/json"); - - base.execute(); } + builder.end_array(); + builder.end_object(); + set_custom_payload(Json.to_string (builder.get_root (), false), "application/json"); + + base.execute(); } } @@ -248,6 +235,7 @@ public class Publisher : Publishing.RESTSupport.GooglePublisher { private bool running = false; private PublishingParameters publishing_parameters; private Spit.Publishing.ProgressCallback progress_reporter; + private size_t creation_offset = 0; public Publisher(Spit.Publishing.Service service, Spit.Publishing.PluginHost host) { @@ -478,15 +466,33 @@ public class Publisher : Publishing.RESTSupport.GooglePublisher { uploader.upload_complete.disconnect(on_upload_complete); uploader.upload_error.disconnect(on_upload_error); + do_media_creation_batch(uploader); + } + + private void do_media_creation_batch(Publishing.RESTSupport.BatchUploader uploader) { + var u = (Uploader) uploader; + + if (creation_offset >= u.upload_tokens.length) { + on_media_creation_complete(); + return; + } + + var end = creation_offset + MAX_BATCH_SIZE < u.upload_tokens.length ? + creation_offset + MAX_BATCH_SIZE : u.upload_tokens.length; + var txn = new MediaCreationTransaction(get_session(), - ((Uploader) uploader).upload_tokens, - ((Uploader) uploader).titles, + u.upload_tokens[creation_offset:end], + u.titles[creation_offset:end], publishing_parameters.get_target_album_entry_id()); - txn.completed.connect(on_media_creation_complete); + txn.completed.connect(() => { + do_media_creation_batch(uploader); + }); + txn.network_error.connect(on_media_creation_error); try { + creation_offset = end; txn.execute(); } catch (Spit.Publishing.PublishingError error) { on_media_creation_error(txn, error); @@ -506,10 +512,7 @@ public class Publisher : Publishing.RESTSupport.GooglePublisher { get_host().post_error(err); } - private void on_media_creation_complete(Publishing.RESTSupport.Transaction txn) { - txn.completed.disconnect(on_media_creation_complete); - txn.network_error.disconnect(on_media_creation_error); - + private void on_media_creation_complete() { if (!is_running()) return; |