From bf55d07580d41532416e77f4be54300f3a5ee1a8 Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Tue, 4 Feb 2020 14:38:49 +0100 Subject: [PATCH 1/3] Re-add sizes.raw to the photo JSON because we need it for showing the raw image in the lightbox. This got lost, as the photo extension was made after API development started. --- app/presenters/photo_presenter.rb | 6 ++++-- lib/schemas/api_v1.json | 3 ++- spec/presenters/photo_presenter_spec.rb | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/presenters/photo_presenter.rb b/app/presenters/photo_presenter.rb index 2d2659400e1..0fa7e9a87fe 100644 --- a/app/presenters/photo_presenter.rb +++ b/app/presenters/photo_presenter.rb @@ -12,7 +12,8 @@ def base_hash sizes: { small: url(:thumb_small), medium: url(:thumb_medium), - large: url(:scaled_full) + large: url(:scaled_full), + raw: url } } end @@ -26,7 +27,8 @@ def as_api_json(full=false) sizes: { small: url(:thumb_small), medium: url(:thumb_medium), - large: url(:scaled_full) + large: url(:scaled_full), + raw: url } } diff --git a/lib/schemas/api_v1.json b/lib/schemas/api_v1.json index 46342dd48be..a8c383417cb 100644 --- a/lib/schemas/api_v1.json +++ b/lib/schemas/api_v1.json @@ -205,11 +205,12 @@ "photo_sizes": { "type": "object", "properties": { + "raw": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/url" }, "large": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/url" }, "medium": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/url" }, "small": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/url" } }, - "required": ["large", "medium", "small"], + "required": ["raw", "large", "medium", "small"], "additionalProperties": true }, diff --git a/spec/presenters/photo_presenter_spec.rb b/spec/presenters/photo_presenter_spec.rb index e5bcb5677db..840a8ed71fd 100644 --- a/spec/presenters/photo_presenter_spec.rb +++ b/spec/presenters/photo_presenter_spec.rb @@ -34,6 +34,7 @@ def confirm_photo_format(photo, ref_photo) expect(photo[:sizes][:small]).to be_truthy expect(photo[:sizes][:medium]).to be_truthy expect(photo[:sizes][:large]).to be_truthy + expect(photo[:sizes][:raw]).to be_truthy end # rubocop:enable Metrics/AbcSize end From 9e0c774b440a80200f089758107a1df3a578f5da Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Tue, 4 Feb 2020 14:38:49 +0100 Subject: [PATCH 2/3] Add the scaled_full image as a raw image in AvatarPresenter as well. This is a temporary workaround. Adding the real raw photo is quite a challange and touches multiple components nobody wants to touch right now. As this change is blocking an actual hotfix, this is fine, and will be properly fixed at a later time. --- app/presenters/avatar_presenter.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/presenters/avatar_presenter.rb b/app/presenters/avatar_presenter.rb index c3656cc69a5..5b1b71f3956 100644 --- a/app/presenters/avatar_presenter.rb +++ b/app/presenters/avatar_presenter.rb @@ -6,7 +6,8 @@ def base_hash(with_default=false) avatar = { small: small(with_default), medium: medium(with_default), - large: large(with_default) + large: large(with_default), + raw: raw(with_default) }.compact avatar unless avatar.empty? @@ -21,6 +22,11 @@ def medium(with_default=false) end def large(with_default=false) + image_url(size: :scaled_full, fallback_to_default: with_default) + end + + def raw(with_default=false) + # ToDo: Replace me with the actual raw photo. image_url(fallback_to_default: with_default) end end From bcbcee14c0550b09501778a3346daf7b2d80ea5a Mon Sep 17 00:00:00 2001 From: Dennis Schubert Date: Tue, 4 Feb 2020 14:38:49 +0100 Subject: [PATCH 3/3] Do not allow additional properties in the API's photo_sizes schema definition --- lib/schemas/api_v1.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/schemas/api_v1.json b/lib/schemas/api_v1.json index a8c383417cb..84511bd4a8c 100644 --- a/lib/schemas/api_v1.json +++ b/lib/schemas/api_v1.json @@ -211,7 +211,7 @@ "small": { "$ref": "https://diaspora.software/api/v1/schema.json#/definitions/url" } }, "required": ["raw", "large", "medium", "small"], - "additionalProperties": true + "additionalProperties": false }, "photo_dimensions": {