Fix #5311: Unexpected error: Module::DelegationError on failed media assets.

This commit is contained in:
evazion
2022-11-29 01:39:14 -06:00
parent 2836b4b929
commit 580cc3bc9a
4 changed files with 38 additions and 21 deletions

View File

@@ -6,7 +6,13 @@
100% 100%
</div> </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> <p>Image unavailable.</p>
<% elsif is_image? %> <% 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" -%> <%= 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" -%>

View File

@@ -21,7 +21,7 @@ class MediaAsset < ApplicationRecord
has_many :uploaders, through: :uploads, class_name: "User", foreign_key: :uploader_id has_many :uploaders, through: :uploads, class_name: "User", foreign_key: :uploader_id
has_many :ai_tags 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 delegate :is_non_repeating_animation?, :is_greyscale?, :is_rotated?, :is_ai_generated?, :has_sound?, to: :metadata
scope :public_only, -> { where(is_public: true) } scope :public_only, -> { where(is_public: true) }

View File

@@ -34,6 +34,7 @@
</div> </div>
<div class="media-asset-sidebar md:w-360px"> <div class="media-asset-sidebar md:w-360px">
<% if @media_asset.ai_tags.present? %>
<div> <div>
<h3>Tags</h3> <h3>Tags</h3>
@@ -54,6 +55,7 @@
<% end %> <% end %>
</ul> </ul>
</div> </div>
<% end %>
<div> <div>
<table class="striped text-xs w-full"> <table class="striped text-xs w-full">
@@ -104,7 +106,7 @@
</tr> </tr>
<% end %> <% 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> <tr>
<th colspan="2" class="text-center"><%= group.split(/[ _-]/).map(&:upcase_first).join(" ") %></th> <th colspan="2" class="text-center"><%= group.split(/[ _-]/).map(&:upcase_first).join(" ") %></th>
</tr> </tr>

View File

@@ -21,7 +21,9 @@ class MediaAssetsControllerTest < ActionDispatch::IntegrationTest
context "show action" do context "show action" do
should "render" do should "render" do
@media_asset = create(:media_asset) @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 assert_response :success
end end
@@ -34,6 +36,13 @@ class MediaAssetsControllerTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
assert_nil(response.parsed_body[:md5]) assert_nil(response.parsed_body[:md5])
end 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 end
end end