mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:03:22 +08:00
fb0e656cb7
Why this change? One Ruby class per file improves readability
47 lines
946 B
Ruby
47 lines
946 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ThemeSettingsManager::Upload < ThemeSettingsManager
|
|
def value
|
|
has_record? ? cdn_url(db_record.value) : default
|
|
end
|
|
|
|
def default
|
|
upload_id = default_upload_id
|
|
return if upload_id.blank?
|
|
|
|
cdn_url(upload_id)
|
|
end
|
|
|
|
def value=(new_value)
|
|
if new_value.present?
|
|
if new_value == default
|
|
new_value = default_upload_id
|
|
else
|
|
upload = ::Upload.find_by(url: new_value)
|
|
new_value = upload.id if upload.present?
|
|
end
|
|
end
|
|
|
|
super(new_value)
|
|
end
|
|
|
|
private
|
|
|
|
def cdn_url(upload_id)
|
|
return if upload_id.blank?
|
|
|
|
upload = ::Upload.find_by_id(upload_id.to_i)
|
|
return if upload.blank?
|
|
|
|
Discourse.store.cdn_url(upload.url)
|
|
end
|
|
|
|
def default_upload_id
|
|
theme_field =
|
|
theme.theme_fields.find_by(name: @default, type_id: ThemeField.types[:theme_upload_var])
|
|
return if theme_field.blank?
|
|
|
|
theme_field.upload_id
|
|
end
|
|
end
|