show pending messages on posts

This commit is contained in:
Dylan Knutson
2025-07-25 19:15:58 +00:00
parent bd6246d29a
commit 56ed78faaf
7 changed files with 102 additions and 7 deletions

View File

@@ -2,4 +2,4 @@ rails: RAILS_ENV=staging HTTP_PORT=3001 bundle exec thrust ./bin/rails server
wp-client: RAILS_ENV=development HMR=true ./bin/webpacker-dev-server
wp-server: RAILS_ENV=development HMR=true SERVER_BUNDLE_ONLY=yes ./bin/webpacker --watch
css: RAILS_ENV=development yarn "build:css[debug]" --watch
prometheus_exporter: RAILS_ENV=staging bundle exec prometheus_exporter --bind 0.0.0.0 --prefix redux_ --label '{"environment": "staging"}'
prometheus-exporter: RAILS_ENV=staging bundle exec prometheus_exporter --bind 0.0.0.0 --prefix redux_ --label '{"environment": "staging"}'

View File

@@ -75,10 +75,12 @@ module Domain::PostsHelper
file
end
sig { params(post: Domain::Post).returns(T.nilable(String)) }
sig { params(post: Domain::Post).returns(T.any(T.nilable(String), Symbol)) }
def gallery_file_info_for_post(post)
return :post_pending if post.pending_scan?
file = post.primary_file_for_view
return nil unless file.present?
return :file_pending if file.state_pending?
return nil unless file.state_ok?
return nil unless file.log_entry_id.present?
content_type = file.log_entry&.content_type || ""

View File

@@ -162,6 +162,11 @@ class Domain::Post < ReduxApplicationRecord
:id
end
sig { overridable.returns(T::Boolean) }
def pending_scan?
false
end
sig { abstract.returns(T.nilable(String)) }
def title
end

View File

@@ -100,6 +100,11 @@ class Domain::Post::FaPost < Domain::Post
self.file
end
sig { override.returns(T::Boolean) }
def pending_scan?
scanned_at.nil?
end
sig { override.returns(T.nilable(String)) }
def description_html_for_view
description

View File

@@ -13,10 +13,16 @@
alt: post.title_for_view %>
<% end %>
<% elsif file_info = gallery_file_info_for_post(post) %>
<div class="flex items-center border border-slate-200 rounded-md px-3 py-2 bg-slate-100 shadow-sm">
<i class="fas fa-file-alt text-slate-400 mr-2"></i>
<span class="text-sm text-slate-500 italic"><%= file_info %>, <%= gallery_file_size_for_post(post) %></span>
</div>
<% if file_info == :post_pending %>
<span class="text-sm text-slate-500 italic">Post pending scan</span>
<% elsif file_info == :file_pending %>
<span class="text-sm text-slate-500 italic">File pending download</span>
<% else %>
<div class="flex items-center border border-slate-200 rounded-md px-3 py-2 bg-slate-100 shadow-sm">
<i class="fas fa-file-alt text-slate-400 mr-2"></i>
<span class="text-sm text-slate-500 italic"><%= file_info %>, <%= gallery_file_size_for_post(post) %></span>
</div>
<% end %>
<% else %>
<span class="text-sm text-slate-500 italic">No file available</span>
<% end %>

View File

@@ -1,6 +1,7 @@
<% if policy(post).view_file? %>
<% file = post.primary_file_for_view %>
<section>
<% if (log_entry = post.primary_file_for_view&.log_entry) %>
<% if file.present? && (log_entry = file.log_entry) %>
<% if log_entry.status_code == 200 %>
<%= render partial: "log_entries/content_container",
locals: {
@@ -19,6 +20,13 @@
</div>
</section>
<% end %>
<% elsif file.present? && file.state_pending? %>
<section class="flex grow justify-center text-slate-500">
<div>
<i class="fa-solid fa-file-arrow-down"></i>
File pending download
</div>
</section>
<% else %>
<section class="flex grow justify-center overflow-clip">
<div class="text-slate-500">

View File

@@ -14,6 +14,43 @@ RSpec.describe Domain::PostsController, type: :controller do
allow(controller).to receive(:authorize).and_return(true)
end
describe "GET #index" do
it "returns a successful response and renders the index template" do
get :index
expect(response).to be_successful
expect(response).to render_template(:index)
end
context "when post is pending scan" do
let!(:post_pending_scan) do
create(
:domain_post_fa_post,
scanned_at: nil,
title: "Test Post Pending Scan",
)
end
it "displays 'Post pending scan' message" do
get :index
expect(response.body).to include("Post pending scan")
end
end
context "when post file is pending download" do
let!(:post_with_pending_file) do
create(
:domain_post_fa_post,
title: "Test Post with Pending File",
).tap { |post| create(:domain_post_file, post: post, state: "pending") }
end
it "displays 'File pending download' message" do
get :index
expect(response.body).to include("File pending download")
end
end
end
describe "GET #show" do
shared_examples "a post" do
it "returns a successful response and renders the show template" do
@@ -37,6 +74,38 @@ RSpec.describe Domain::PostsController, type: :controller do
let(:post) { create(:domain_post_e621_post) }
it_behaves_like "a post"
end
context "when post file is pending download" do
let(:post) do
create(
:domain_post_fa_post,
title: "Test Post with Pending File",
).tap do |post|
create(
:domain_post_file,
post: post,
state: "pending",
url_str: "https://example.com/image.jpg",
)
end
end
it "displays 'File pending download' message" do
get :show, params: { id: post.to_param }
expect(response.body).to include("File pending download")
end
end
context "when post has no file" do
let(:post) do
create(:domain_post_fa_post, title: "Test Post with No File")
end
it "displays 'No file' message" do
get :show, params: { id: post.to_param }
expect(response.body).to include("No file")
end
end
end
describe "GET #visual_search" do