diff --git a/app/serializers/upload_serializer.rb b/app/serializers/upload_serializer.rb index eb32b011813..828721c97b2 100644 --- a/app/serializers/upload_serializer.rb +++ b/app/serializers/upload_serializer.rb @@ -16,6 +16,12 @@ class UploadSerializer < ApplicationSerializer :human_filesize, :dominant_color + has_one :thumbnail, + serializer: UploadThumbnailSerializer, + root: false, + embed: :object, + if: -> { SiteSetting.create_thumbnails && object.has_thumbnail? } + def url if object.for_site_setting object.url diff --git a/app/serializers/upload_thumbnail_serializer.rb b/app/serializers/upload_thumbnail_serializer.rb new file mode 100644 index 00000000000..6b4e0ae07ba --- /dev/null +++ b/app/serializers/upload_thumbnail_serializer.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class UploadThumbnailSerializer < ApplicationSerializer + attributes :id, :upload_id, :width, :height, :url, :extension, :filesize +end diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb index 827fe68c63d..aa6f3a855b8 100644 --- a/plugins/chat/plugin.rb +++ b/plugins/chat/plugin.rb @@ -272,12 +272,6 @@ after_initialize do object.chat_separate_sidebar_mode end - add_to_serializer( - :upload, - :thumbnail, - include_condition: -> { SiteSetting.chat_enabled && SiteSetting.create_thumbnails }, - ) { object.thumbnail } - on(:site_setting_changed) do |name, old_value, new_value| user_option_field = Chat::RETENTION_SETTINGS_TO_USER_OPTION_FIELDS[name.to_sym] begin diff --git a/spec/requests/api/schemas/json/upload_create_response.json b/spec/requests/api/schemas/json/upload_create_response.json index 32f92c5d7d9..09791cde016 100644 --- a/spec/requests/api/schemas/json/upload_create_response.json +++ b/spec/requests/api/schemas/json/upload_create_response.json @@ -42,6 +42,33 @@ }, "dominant_color": { "type": ["string", "null"] + }, + "thumbnail": { + "type": ["object", "null"], + "additionalProperties": false, + "properties": { + "id": { + "type": "integer" + }, + "upload_id": { + "type": "integer" + }, + "url": { + "type": "string" + }, + "extension": { + "type": "string" + }, + "width": { + "type": "integer" + }, + "height": { + "type": "integer" + }, + "filesize": { + "type": "integer" + } + } } }, "required": [