diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2022-10-02 20:33:39 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2022-10-02 20:33:39 +0200 |
commit | ac6e0b731b9f0b2efd392e3309a5c07e2a66adad (patch) | |
tree | d3225c4f583bbc2dd2d4d1270599bdc91d6bbb57 /plugins/shotwell-publishing | |
parent | beb8b0dad71871aa66b63901b3e6b6c047e1a646 (diff) | |
parent | 133064a8fce1a02e83874295ab20ab1dee304777 (diff) |
Merge branch 'release/debian/0.30.17-1'debian/0.30.17-1
Diffstat (limited to 'plugins/shotwell-publishing')
-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; |