2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
class UploadSerializer < ApplicationSerializer
|
2017-08-23 04:40:01 +08:00
|
|
|
attributes :id,
|
|
|
|
:url,
|
|
|
|
:original_filename,
|
|
|
|
:filesize,
|
|
|
|
:width,
|
|
|
|
:height,
|
2018-08-28 10:48:43 +08:00
|
|
|
:thumbnail_width,
|
|
|
|
:thumbnail_height,
|
2017-08-23 04:40:01 +08:00
|
|
|
:extension,
|
|
|
|
:short_url,
|
2020-04-15 07:19:59 +08:00
|
|
|
:short_path,
|
2019-02-21 10:13:37 +08:00
|
|
|
:retain_hours,
|
2022-09-20 17:28:17 +08:00
|
|
|
:human_filesize,
|
|
|
|
:dominant_color
|
2020-01-16 11:50:27 +08:00
|
|
|
|
2024-10-18 16:55:14 +08:00
|
|
|
has_one :thumbnail,
|
|
|
|
serializer: UploadThumbnailSerializer,
|
|
|
|
root: false,
|
|
|
|
embed: :object,
|
|
|
|
if: -> { SiteSetting.create_thumbnails && object.has_thumbnail? }
|
|
|
|
|
2020-01-16 11:50:27 +08:00
|
|
|
def url
|
2022-09-29 07:24:33 +08:00
|
|
|
if object.for_site_setting
|
|
|
|
object.url
|
2023-01-09 20:20:10 +08:00
|
|
|
else
|
2022-09-29 07:24:33 +08:00
|
|
|
UrlHelper.cook_url(object.url, secure: SiteSetting.secure_uploads? && object.secure)
|
2023-01-09 20:20:10 +08:00
|
|
|
end
|
2020-01-16 11:50:27 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|