Fix #5311: Unexpected error: Module::DelegationError on failed media assets.
This commit is contained in:
@@ -6,7 +6,13 @@
|
||||
100%
|
||||
</div>
|
||||
|
||||
<% if !policy(media_asset).can_see_image? %>
|
||||
<% if media_asset.expunged? || media_asset.deleted? %>
|
||||
<p>Image deleted.</p>
|
||||
<% elsif media_asset.processing? %>
|
||||
<p><%= spinner_icon(class: "h-8") %></p>
|
||||
<% elsif media_asset.failed? %>
|
||||
<p>Upload failed.</p>
|
||||
<% elsif !media_asset.active? || !policy(media_asset).can_see_image? %>
|
||||
<p>Image unavailable.</p>
|
||||
<% elsif is_image? %>
|
||||
<%= tag.img src: variant(:original).file_url, width: image_width, height: image_height, draggable: "false", class: "media-asset-image max-h-inherit max-w-full h-full w-auto select-none" -%>
|
||||
|
||||
@@ -21,7 +21,7 @@ class MediaAsset < ApplicationRecord
|
||||
has_many :uploaders, through: :uploads, class_name: "User", foreign_key: :uploader_id
|
||||
has_many :ai_tags
|
||||
|
||||
delegate :frame_delays, :metadata, to: :media_metadata
|
||||
delegate :frame_delays, :metadata, to: :media_metadata, allow_nil: true
|
||||
delegate :is_non_repeating_animation?, :is_greyscale?, :is_rotated?, :is_ai_generated?, :has_sound?, to: :metadata
|
||||
|
||||
scope :public_only, -> { where(is_public: true) }
|
||||
|
||||
@@ -34,26 +34,28 @@
|
||||
</div>
|
||||
|
||||
<div class="media-asset-sidebar md:w-360px">
|
||||
<div>
|
||||
<h3>Tags</h3>
|
||||
<% if @media_asset.ai_tags.present? %>
|
||||
<div>
|
||||
<h3>Tags</h3>
|
||||
|
||||
<ul class="tag-list categorized-tag-list">
|
||||
<% @media_asset.ai_tags.undeprecated.sort_by { |tag| [TagCategory.split_header_list.index(tag.category_name.downcase), tag.name.starts_with?("rating:") ? 0 : 1, tag.name] }.each do |ai_tag| %>
|
||||
<%= tag.li class: "tag-type-#{ai_tag.category} space-x-1 text-sm", "data-tag-name": ai_tag.name do %>
|
||||
<% if ai_tag.tag.artist? %>
|
||||
<%= link_to "?", show_or_new_artists_path(name: ai_tag.name) %>
|
||||
<% elsif ai_tag.name =~ /\A\d+\z/ %>
|
||||
<%= link_to "?", wiki_page_path("~#{ai_tag.name}") %>
|
||||
<% else %>
|
||||
<%= link_to "?", wiki_page_path(ai_tag.name) %>
|
||||
<ul class="tag-list categorized-tag-list">
|
||||
<% @media_asset.ai_tags.undeprecated.sort_by { |tag| [TagCategory.split_header_list.index(tag.category_name.downcase), tag.name.starts_with?("rating:") ? 0 : 1, tag.name] }.each do |ai_tag| %>
|
||||
<%= tag.li class: "tag-type-#{ai_tag.category} space-x-1 text-sm", "data-tag-name": ai_tag.name do %>
|
||||
<% if ai_tag.tag.artist? %>
|
||||
<%= link_to "?", show_or_new_artists_path(name: ai_tag.name) %>
|
||||
<% elsif ai_tag.name =~ /\A\d+\z/ %>
|
||||
<%= link_to "?", wiki_page_path("~#{ai_tag.name}") %>
|
||||
<% else %>
|
||||
<%= link_to "?", wiki_page_path(ai_tag.name) %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to ai_tag.pretty_name, media_assets_path(search: { ai_tags_match: ai_tag.name }), class: "break-word" %>
|
||||
<%= tag.span "#{ai_tag.score}%", class: ["text-muted text-xs"] %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to ai_tag.pretty_name, media_assets_path(search: { ai_tags_match: ai_tag.name }), class: "break-word" %>
|
||||
<%= tag.span "#{ai_tag.score}%", class: ["text-muted text-xs"] %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div>
|
||||
<table class="striped text-xs w-full">
|
||||
@@ -104,7 +106,7 @@
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<% @media_asset.metadata.group_by { |key, value| key.split(":").first }.sort.each do |group, pairs| %>
|
||||
<% @media_asset.metadata.to_h.group_by { |key, value| key.split(":").first }.sort.each do |group, pairs| %>
|
||||
<tr>
|
||||
<th colspan="2" class="text-center"><%= group.split(/[ _-]/).map(&:upcase_first).join(" ") %></th>
|
||||
</tr>
|
||||
|
||||
@@ -21,7 +21,9 @@ class MediaAssetsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "show action" do
|
||||
should "render" do
|
||||
@media_asset = create(:media_asset)
|
||||
get media_asset_path(@media_asset), as: :json
|
||||
@ai_tags = create_list(:ai_tag, 10, media_asset: @media_asset)
|
||||
|
||||
get media_asset_path(@media_asset)
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
@@ -34,6 +36,13 @@ class MediaAssetsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
assert_nil(response.parsed_body[:md5])
|
||||
end
|
||||
|
||||
should "work for a deleted asset" do
|
||||
@media_asset = create(:media_asset, status: "deleted", media_metadata: nil)
|
||||
get media_asset_path(@media_asset)
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user