diff --git a/app/controllers/iqdb_queries_controller.rb b/app/controllers/iqdb_queries_controller.rb index b9aae52c0..62a9b93a5 100644 --- a/app/controllers/iqdb_queries_controller.rb +++ b/app/controllers/iqdb_queries_controller.rb @@ -49,7 +49,7 @@ protected def create_by_post @post = Post.find(params[:post_id]) - @download = Iqdb::Download.new(@post.complete_preview_file_url) + @download = Iqdb::Download.new(@post.preview_file_url) @download.find_similar @results = @download.matches end diff --git a/app/models/post.rb b/app/models/post.rb index c6b3d178f..9e6a211e0 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -130,38 +130,6 @@ class Post < ApplicationRecord backup_storage_manager.store_file(preview_file, self, :preview) if preview_file.present? end - def file_path_prefix - Rails.env == "test" ? "test." : "" - end - - def file_path - "#{Rails.root}/public/data/#{file_path_prefix}#{md5}.#{file_ext}" - end - - def large_file_path - if has_large? - "#{Rails.root}/public/data/sample/#{file_path_prefix}#{Danbooru.config.large_image_prefix}#{md5}.#{large_file_ext}" - else - file_path - end - end - - def large_file_ext - if is_ugoira? - "webm" - else - "jpg" - end - end - - def preview_file_path - "#{Rails.root}/public/data/preview/#{file_path_prefix}#{md5}.jpg" - end - - def file_name - "#{file_path_prefix}#{md5}.#{file_ext}" - end - def backup_storage_manager Danbooru.config.backup_storage_manager end @@ -178,10 +146,6 @@ class Post < ApplicationRecord storage_manager.file_url(self, :original) end - # this is for the 640x320 version - def cropped_file_url - end - def large_file_url storage_manager.file_url(self, :large) end @@ -190,10 +154,6 @@ class Post < ApplicationRecord storage_manager.file_url(self, :preview) end - def complete_preview_file_url - "http://#{Danbooru.config.hostname}#{preview_file_url}" - end - def open_graph_image_url if is_image? if has_large? @@ -202,7 +162,7 @@ class Post < ApplicationRecord file_url end else - complete_preview_file_url + preview_file_url end end @@ -214,14 +174,6 @@ class Post < ApplicationRecord end end - def file_path_for(user) - if user.default_image_size == "large" && image_width > Danbooru.config.large_image_width - large_file_path - else - file_path - end - end - def is_image? file_ext =~ /jpg|jpeg|gif|png/i end @@ -247,9 +199,7 @@ class Post < ApplicationRecord end def has_preview? - # for video/ugoira we don't want to try and render a preview that - # might doesn't exist yet - is_image? || ((is_video? || is_ugoira?) && File.exists?(preview_file_path)) + is_image? || is_video? || is_ugoira? end def has_dimensions? @@ -257,7 +207,7 @@ class Post < ApplicationRecord end def has_ugoira_webm? - created_at < 1.minute.ago || (File.exists?(preview_file_path) && File.size(preview_file_path) > 0) + true end end @@ -1674,8 +1624,8 @@ class Post < ApplicationRecord end def update_iqdb_async - if File.exists?(preview_file_path) && Post.iqdb_enabled? - Post.iqdb_sqs_service.send_message("update\n#{id}\n#{complete_preview_file_url}") + if Post.iqdb_enabled? + Post.iqdb_sqs_service.send_message("update\n#{id}\n#{preview_file_url}") end end diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 4fe901fbb..e0c70520a 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -135,6 +135,10 @@ class PostPresenter < Presenter @post.humanized_essential_tag_string end + def filename_for_download + "#{humanized_essential_tag_string} - #{@post.md5}.#{@post.file_ext}" + end + def categorized_tag_groups string = [] diff --git a/app/views/comments/index.atom.builder b/app/views/comments/index.atom.builder index 09d017868..19e1c8b75 100644 --- a/app/views/comments/index.atom.builder +++ b/app/views/comments/index.atom.builder @@ -11,7 +11,7 @@ atom_feed(root_url: comments_url(host: Danbooru.config.hostname)) do |feed| feed.entry(comment, published: comment.created_at, updated: comment.updated_at) do |entry| entry.title("@#{comment.creator_name} on post ##{comment.post_id} (#{comment.post.humanized_essential_tag_string})") entry.content(<<-EOS.strip_heredoc, type: "html") - + #{format_text(comment.body)} EOS diff --git a/app/views/posts/partials/show/_options.html.erb b/app/views/posts/partials/show/_options.html.erb index 81350deaa..79d83588d 100644 --- a/app/views/posts/partials/show/_options.html.erb +++ b/app/views/posts/partials/show/_options.html.erb @@ -4,7 +4,7 @@ <% if CurrentUser.is_member? %>
  • <%= link_to "Favorite", favorites_path(:post_id => post.id), :remote => true, :method => :post, :id => "add-to-favorites", :title => "Shortcut is F" %>
  • <%= link_to "Unfavorite", favorite_path(post), :remote => true, :method => :delete, :id => "remove-from-favorites" %>
  • -
  • <%= link_to_if post.visible?, "Download", post.file_url, :download => post.presenter.humanized_essential_tag_string + " - " + post.file_name %>
  • +
  • <%= link_to_if post.visible?, "Download", post.file_url, download: post.presenter.filename_for_download %>
  • <%= link_to "Add to pool", "#", :id => "pool" %>
  • <% if post.is_note_locked? %>
  • Note locked
  • diff --git a/test/test_helpers/iqdb_test_helper.rb b/test/test_helpers/iqdb_test_helper.rb index 9bcdec4f4..edd941f6e 100644 --- a/test/test_helpers/iqdb_test_helper.rb +++ b/test/test_helpers/iqdb_test_helper.rb @@ -23,7 +23,7 @@ module IqdbTestHelper end def mock_iqdb_matches!(post_or_source, matches) - source = post_or_source.is_a?(Post) ? post_or_source.complete_preview_file_url : post_or_source + source = post_or_source.is_a?(Post) ? post_or_source.preview_file_url : post_or_source url = "http://localhost:3004/similar?key=hunter2&url=#{CGI.escape source}&ref" body = matches.map { |post| { post_id: post.id } }.to_json