posts: remove unused file path / url methods.

* Remove file_path_for, cropped_file_url (dead code)
* Remove complete_preview_file_url (preview_file_url now returns absolute links)
* Remove `file_name` (only used for Download link in sidebar)
This commit is contained in:
evazion
2018-03-18 18:11:44 -05:00
parent b7f7187f63
commit 41a4ff15cd
6 changed files with 13 additions and 59 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 = []

View File

@@ -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")
<img src="#{comment.post.complete_preview_file_url}"/>
<img src="#{comment.post.preview_file_url}"/>
#{format_text(comment.body)}
EOS

View File

@@ -4,7 +4,7 @@
<% if CurrentUser.is_member? %>
<li><%= link_to "Favorite", favorites_path(:post_id => post.id), :remote => true, :method => :post, :id => "add-to-favorites", :title => "Shortcut is F" %></li>
<li><%= link_to "Unfavorite", favorite_path(post), :remote => true, :method => :delete, :id => "remove-from-favorites" %></li>
<li><%= link_to_if post.visible?, "Download", post.file_url, :download => post.presenter.humanized_essential_tag_string + " - " + post.file_name %></li>
<li><%= link_to_if post.visible?, "Download", post.file_url, download: post.presenter.filename_for_download %></li>
<li id="add-to-pool-list"><%= link_to "Add to pool", "#", :id => "pool" %></li>
<% if post.is_note_locked? %>
<li id="add-notes-list"><span id="note-locked-notice">Note locked</span></li>

View File

@@ -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