mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 20:03:54 +08:00
16acba6cf8
Since we recently blocked accidental serialization of AR models, we are getting a 500 error in some cases with thumbnails. We can fix this by serializing the thumbnail, previously we just returned a raw OptimizedImage object. Thumbnails are now attached to the serializer in core, therefore we no longer need to use add_to_serializer within the chat plugin to use thumbnails within chat message uploads.
33 lines
815 B
Ruby
33 lines
815 B
Ruby
# frozen_string_literal: true
|
|
|
|
class UploadSerializer < ApplicationSerializer
|
|
attributes :id,
|
|
:url,
|
|
:original_filename,
|
|
:filesize,
|
|
:width,
|
|
:height,
|
|
:thumbnail_width,
|
|
:thumbnail_height,
|
|
:extension,
|
|
:short_url,
|
|
:short_path,
|
|
:retain_hours,
|
|
: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
|
|
else
|
|
UrlHelper.cook_url(object.url, secure: SiteSetting.secure_uploads? && object.secure)
|
|
end
|
|
end
|
|
end
|