posts: fix placeholder thumbnail for Flash files.
* Replace the "Download" placeholder thumbnail for Flash files with a new placeholder that specifically says it's a Flash file. * Fix a bug where the Flash placeholder thumbnail was too small when using larger thumbnail sizes. * Fix it so that media assets don't falsely consider Flash files to have thumbnails. This could potentially cause errors if someone tried to expunge, replace, or regenerate a Flash post.
This commit is contained in:
@@ -17,16 +17,20 @@
|
||||
<% end %>
|
||||
|
||||
<picture>
|
||||
<% unless save_data %>
|
||||
<% case size %>
|
||||
<% when 150, 180 %>
|
||||
<%= tag.source type: "image/jpeg", srcset: "#{media_asset.variant("180x180").file_url} 1x, #{media_asset.variant("360x360").file_url} 2x" %>
|
||||
<% when 225, 270, 360 %>
|
||||
<%= tag.source type: "image/webp", srcset: "#{media_asset.variant("360x360").file_url} 1x, #{media_asset.variant("720x720").file_url} 2x" %>
|
||||
<% if media_asset.is_flash? %>
|
||||
<%= tag.img src: "images/flash-preview.png", class: "media-asset-preview-image w-auto h-auto max-h-#{size}px max-w-full", draggable: "false" -%>
|
||||
<% else %>
|
||||
<% unless save_data %>
|
||||
<% case size %>
|
||||
<% when 150, 180 %>
|
||||
<%= tag.source type: "image/jpeg", srcset: "#{media_asset.variant("180x180").file_url} 1x, #{media_asset.variant("360x360").file_url} 2x" %>
|
||||
<% when 225, 270, 360 %>
|
||||
<%= tag.source type: "image/webp", srcset: "#{media_asset.variant("360x360").file_url} 1x, #{media_asset.variant("720x720").file_url} 2x" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= tag.img src: variant.file_url, width: variant.width, height: variant.height, class: "media-asset-preview-image w-auto h-auto max-h-#{size}px max-w-full", draggable: "false" -%>
|
||||
<%= tag.img src: variant.file_url, width: variant.width, height: variant.height, class: "media-asset-preview-image w-auto h-auto max-h-#{size}px max-w-full", draggable: "false" -%>
|
||||
<% end %>
|
||||
</picture>
|
||||
<% else %>
|
||||
<div class="media-asset-placeholder rounded border border-solid flex items-center justify-center w-<%= size %>px h-<%= size %>px">
|
||||
|
||||
@@ -15,16 +15,20 @@
|
||||
<% end %>
|
||||
|
||||
<picture>
|
||||
<% unless save_data %>
|
||||
<% case size %>
|
||||
<% when "150", "180" %>
|
||||
<%= tag.source type: "image/jpeg", srcset: "#{media_asset.variant("180x180").file_url} 1x, #{media_asset.variant("360x360").file_url} 2x" %>
|
||||
<% when "225", "225w", "270", "270w", "360" %>
|
||||
<%= tag.source type: "image/webp", srcset: "#{media_asset.variant("360x360").file_url} 1x, #{media_asset.variant("720x720").file_url} 2x" %>
|
||||
<% if media_asset.is_flash? %>
|
||||
<%= tag.img src: "/images/flash-preview.png", class: "post-preview-image", title: tooltip, alt: "post ##{post.id}", draggable: "false" -%>
|
||||
<% else %>
|
||||
<% unless save_data %>
|
||||
<% case size %>
|
||||
<% when "150", "180" %>
|
||||
<%= tag.source type: "image/jpeg", srcset: "#{media_asset.variant("180x180").file_url} 1x, #{media_asset.variant("360x360").file_url} 2x" %>
|
||||
<% when "225", "225w", "270", "270w", "360" %>
|
||||
<%= tag.source type: "image/webp", srcset: "#{media_asset.variant("360x360").file_url} 1x, #{media_asset.variant("720x720").file_url} 2x" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= tag.img src: variant.file_url, width: variant.width, height: variant.height, class: "post-preview-image", title: tooltip, alt: "post ##{post.id}", draggable: "false" -%>
|
||||
<%= tag.img src: variant.file_url, width: variant.width, height: variant.height, class: "post-preview-image", title: tooltip, alt: "post ##{post.id}", draggable: "false" -%>
|
||||
<% end %>
|
||||
</picture>
|
||||
<% end -%>
|
||||
</div>
|
||||
|
||||
@@ -58,8 +58,6 @@ class MediaAsset < ApplicationRecord
|
||||
def initialize(media_asset, variant)
|
||||
@media_asset = media_asset
|
||||
@variant = variant.to_sym
|
||||
|
||||
raise ArgumentError, "asset doesn't have #{@variant} variant" unless Variant.exists?(@media_asset, @variant)
|
||||
end
|
||||
|
||||
def store_file!(original_file)
|
||||
@@ -108,13 +106,9 @@ class MediaAsset < ApplicationRecord
|
||||
end
|
||||
|
||||
def file_path(slug = "")
|
||||
if variant.in?(%i[preview 180x180 360x360 720x720]) && media_asset.is_flash?
|
||||
"/images/download-preview.png"
|
||||
else
|
||||
slug = "__#{slug}__" if slug.present?
|
||||
slug = nil if !ENABLE_SEO_POST_URLS
|
||||
"/#{variant}/#{md5[0..1]}/#{md5[2..3]}/#{slug}#{file_name}"
|
||||
end
|
||||
slug = "__#{slug}__" if slug.present?
|
||||
slug = nil if !ENABLE_SEO_POST_URLS
|
||||
"/#{variant}/#{md5[0..1]}/#{md5[2..3]}/#{slug}#{file_name}"
|
||||
end
|
||||
|
||||
# The file name of this variant.
|
||||
@@ -170,23 +164,6 @@ class MediaAsset < ApplicationRecord
|
||||
dimensions[1]
|
||||
end
|
||||
|
||||
def self.exists?(media_asset, variant)
|
||||
case variant
|
||||
when :preview
|
||||
true
|
||||
when :"180x180"
|
||||
true
|
||||
when :"360x360"
|
||||
true
|
||||
when :"720x720"
|
||||
true
|
||||
when :sample
|
||||
media_asset.is_ugoira? || (media_asset.is_static_image? && media_asset.image_width > LARGE_IMAGE_WIDTH)
|
||||
when :original
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
memoize :file_name, :file_ext, :max_dimensions, :dimensions
|
||||
end
|
||||
|
||||
@@ -363,15 +340,27 @@ class MediaAsset < ApplicationRecord
|
||||
|
||||
concerning :VariantMethods do
|
||||
def variant(type)
|
||||
return nil unless has_variant?(type)
|
||||
Variant.new(self, type)
|
||||
end
|
||||
|
||||
def has_variant?(variant)
|
||||
Variant.exists?(self, variant)
|
||||
def has_variant?(type)
|
||||
variant_types.include?(type.to_sym)
|
||||
end
|
||||
|
||||
def variants
|
||||
VARIANTS.select { |v| has_variant?(v) }.map { |v| variant(v) }
|
||||
@variants ||= variant_types.map { |type| variant(type) }
|
||||
end
|
||||
|
||||
def variant_types
|
||||
@variant_types ||=
|
||||
if is_flash?
|
||||
[:original]
|
||||
elsif (is_animated? && !is_ugoira?) || (is_static_image? && image_width <= LARGE_IMAGE_WIDTH)
|
||||
VARIANTS - [:sample]
|
||||
else
|
||||
VARIANTS
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -162,6 +162,8 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def preview_file_url
|
||||
# XXX hack to return placeholder thumbnail for Flash files the /posts.json API.
|
||||
return Danbooru.config.storage_manager.file_url("/images/flash-preview.png") if media_asset.is_flash?
|
||||
media_asset.variant(:preview).file_url
|
||||
end
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB |
BIN
public/images/flash-preview.png
Executable file
BIN
public/images/flash-preview.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Reference in New Issue
Block a user