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 %>
|
<% end %>
|
||||||
|
|
||||||
<picture>
|
<picture>
|
||||||
<% unless save_data %>
|
<% if media_asset.is_flash? %>
|
||||||
<% case size %>
|
<%= 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" -%>
|
||||||
<% when 150, 180 %>
|
<% else %>
|
||||||
<%= tag.source type: "image/jpeg", srcset: "#{media_asset.variant("180x180").file_url} 1x, #{media_asset.variant("360x360").file_url} 2x" %>
|
<% unless save_data %>
|
||||||
<% when 225, 270, 360 %>
|
<% case size %>
|
||||||
<%= tag.source type: "image/webp", srcset: "#{media_asset.variant("360x360").file_url} 1x, #{media_asset.variant("720x720").file_url} 2x" %>
|
<% 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 %>
|
||||||
<% 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>
|
</picture>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="media-asset-placeholder rounded border border-solid flex items-center justify-center w-<%= size %>px h-<%= size %>px">
|
<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 %>
|
<% end %>
|
||||||
|
|
||||||
<picture>
|
<picture>
|
||||||
<% unless save_data %>
|
<% if media_asset.is_flash? %>
|
||||||
<% case size %>
|
<%= tag.img src: "/images/flash-preview.png", class: "post-preview-image", title: tooltip, alt: "post ##{post.id}", draggable: "false" -%>
|
||||||
<% when "150", "180" %>
|
<% else %>
|
||||||
<%= tag.source type: "image/jpeg", srcset: "#{media_asset.variant("180x180").file_url} 1x, #{media_asset.variant("360x360").file_url} 2x" %>
|
<% unless save_data %>
|
||||||
<% when "225", "225w", "270", "270w", "360" %>
|
<% case size %>
|
||||||
<%= tag.source type: "image/webp", srcset: "#{media_asset.variant("360x360").file_url} 1x, #{media_asset.variant("720x720").file_url} 2x" %>
|
<% 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 %>
|
||||||
<% 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>
|
</picture>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -58,8 +58,6 @@ class MediaAsset < ApplicationRecord
|
|||||||
def initialize(media_asset, variant)
|
def initialize(media_asset, variant)
|
||||||
@media_asset = media_asset
|
@media_asset = media_asset
|
||||||
@variant = variant.to_sym
|
@variant = variant.to_sym
|
||||||
|
|
||||||
raise ArgumentError, "asset doesn't have #{@variant} variant" unless Variant.exists?(@media_asset, @variant)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def store_file!(original_file)
|
def store_file!(original_file)
|
||||||
@@ -108,13 +106,9 @@ class MediaAsset < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def file_path(slug = "")
|
def file_path(slug = "")
|
||||||
if variant.in?(%i[preview 180x180 360x360 720x720]) && media_asset.is_flash?
|
slug = "__#{slug}__" if slug.present?
|
||||||
"/images/download-preview.png"
|
slug = nil if !ENABLE_SEO_POST_URLS
|
||||||
else
|
"/#{variant}/#{md5[0..1]}/#{md5[2..3]}/#{slug}#{file_name}"
|
||||||
slug = "__#{slug}__" if slug.present?
|
|
||||||
slug = nil if !ENABLE_SEO_POST_URLS
|
|
||||||
"/#{variant}/#{md5[0..1]}/#{md5[2..3]}/#{slug}#{file_name}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# The file name of this variant.
|
# The file name of this variant.
|
||||||
@@ -170,23 +164,6 @@ class MediaAsset < ApplicationRecord
|
|||||||
dimensions[1]
|
dimensions[1]
|
||||||
end
|
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
|
memoize :file_name, :file_ext, :max_dimensions, :dimensions
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -363,15 +340,27 @@ class MediaAsset < ApplicationRecord
|
|||||||
|
|
||||||
concerning :VariantMethods do
|
concerning :VariantMethods do
|
||||||
def variant(type)
|
def variant(type)
|
||||||
|
return nil unless has_variant?(type)
|
||||||
Variant.new(self, type)
|
Variant.new(self, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_variant?(variant)
|
def has_variant?(type)
|
||||||
Variant.exists?(self, variant)
|
variant_types.include?(type.to_sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
def variants
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def preview_file_url
|
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
|
media_asset.variant(:preview).file_url
|
||||||
end
|
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