diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2021-08-18 20:39:48 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2021-08-18 20:39:48 +0200 |
commit | 9ee94b6fd44e93a3eacdcdef9aa96e245a2c961e (patch) | |
tree | f93c4a826d038302d79959c6507a16aa8c20e2a3 /plugins | |
parent | 29dcf0568d89ade47d70714865d6d917766ec257 (diff) | |
parent | 24cc60499ad147c1897b3b68e0d8e9dde36b013c (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/shotwell-publishing/PhotosPublisher.vala | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/plugins/shotwell-publishing/PhotosPublisher.vala b/plugins/shotwell-publishing/PhotosPublisher.vala index 5f46470..e1127ac 100644 --- a/plugins/shotwell-publishing/PhotosPublisher.vala +++ b/plugins/shotwell-publishing/PhotosPublisher.vala @@ -7,6 +7,7 @@ namespace Publishing.GooglePhotos { internal const string DEFAULT_ALBUM_NAME = N_("Shotwell Connect"); +internal const int MAX_BATCH_SIZE = 50; internal class Album { public string name; @@ -127,28 +128,41 @@ private class MediaCreationTransaction : Publishing.RESTSupport.GooglePublisher. } public override void execute () throws Spit.Publishing.PublishingError { - 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("description"); - builder.add_string_value(this.titles[i]); - builder.set_member_name("simpleMediaItem"); + 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(); builder.begin_object(); - builder.set_member_name("uploadToken"); - builder.add_string_value(this.upload_tokens[i]); - builder.end_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.end_object(); - } - builder.end_array(); - builder.end_object(); - set_custom_payload(Json.to_string (builder.get_root (), false), "application/json"); + set_custom_payload(Json.to_string (builder.get_root (), false), "application/json"); - base.execute(); + base.execute(); + } } } |