mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
DEV: serialize image upload thumbnail (#29276)
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.
This commit is contained in:
parent
7f607699b8
commit
16acba6cf8
|
@ -16,6 +16,12 @@ class UploadSerializer < ApplicationSerializer
|
||||||
:human_filesize,
|
:human_filesize,
|
||||||
:dominant_color
|
:dominant_color
|
||||||
|
|
||||||
|
has_one :thumbnail,
|
||||||
|
serializer: UploadThumbnailSerializer,
|
||||||
|
root: false,
|
||||||
|
embed: :object,
|
||||||
|
if: -> { SiteSetting.create_thumbnails && object.has_thumbnail? }
|
||||||
|
|
||||||
def url
|
def url
|
||||||
if object.for_site_setting
|
if object.for_site_setting
|
||||||
object.url
|
object.url
|
||||||
|
|
5
app/serializers/upload_thumbnail_serializer.rb
Normal file
5
app/serializers/upload_thumbnail_serializer.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class UploadThumbnailSerializer < ApplicationSerializer
|
||||||
|
attributes :id, :upload_id, :width, :height, :url, :extension, :filesize
|
||||||
|
end
|
|
@ -272,12 +272,6 @@ after_initialize do
|
||||||
object.chat_separate_sidebar_mode
|
object.chat_separate_sidebar_mode
|
||||||
end
|
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|
|
on(:site_setting_changed) do |name, old_value, new_value|
|
||||||
user_option_field = Chat::RETENTION_SETTINGS_TO_USER_OPTION_FIELDS[name.to_sym]
|
user_option_field = Chat::RETENTION_SETTINGS_TO_USER_OPTION_FIELDS[name.to_sym]
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -42,6 +42,33 @@
|
||||||
},
|
},
|
||||||
"dominant_color": {
|
"dominant_color": {
|
||||||
"type": ["string", "null"]
|
"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": [
|
"required": [
|
||||||
|
|
Loading…
Reference in New Issue
Block a user