diff --git a/app/logical/storage_manager.rb b/app/logical/storage_manager.rb index b7a05c271..dcc2b044c 100644 --- a/app/logical/storage_manager.rb +++ b/app/logical/storage_manager.rb @@ -48,18 +48,19 @@ class StorageManager open(file_path(post.md5, post.file_ext, type)) end - def file_url(post, type) + def file_url(post, type, tagged_filenames: false) subdir = subdir_for(post.md5) file = file_name(post.md5, post.file_ext, type) + seo_tags = seo_tags(post) if tagged_filenames if type == :preview && !post.has_preview? "#{base_url}/images/download-preview.png" elsif type == :preview "#{base_url}/preview/#{subdir}#{file}" elsif type == :large && post.has_large? - "#{base_url}/sample/#{subdir}#{seo_tags(post)}#{file}" + "#{base_url}/sample/#{subdir}#{seo_tags}#{file}" else - "#{base_url}/#{subdir}#{seo_tags(post)}#{post.md5}.#{post.file_ext}" + "#{base_url}/#{subdir}#{seo_tags}#{post.md5}.#{post.file_ext}" end end @@ -100,8 +101,8 @@ class StorageManager end end - def seo_tags(post, user = CurrentUser.user) - return "" if !tagged_filenames || user.disable_tagged_filenames? + def seo_tags(post) + return "" if !tagged_filenames tags = post.humanized_essential_tag_string.gsub(/[^a-z0-9]+/, "_").gsub(/(?:^_+)|(?:_+$)/, "").gsub(/_{2,}/, "_") "__#{tags}__" diff --git a/app/models/post.rb b/app/models/post.rb index cff08f51b..d445030a1 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -145,6 +145,14 @@ class Post < ApplicationRecord storage_manager.open_file(self, type) end + def tagged_file_url + storage_manager.file_url(self, :original, tagged_filenames: !CurrentUser.user.disable_tagged_filenames?) + end + + def tagged_large_file_url + storage_manager.file_url(self, :large, tagged_filenames: !CurrentUser.user.disable_tagged_filenames?) + end + def file_url storage_manager.file_url(self, :original) end @@ -171,9 +179,9 @@ class Post < ApplicationRecord def file_url_for(user) if user.default_image_size == "large" && image_width > Danbooru.config.large_image_width - large_file_url + tagged_large_file_url else - file_url + tagged_file_url end end diff --git a/app/views/posts/partials/show/_download.html.erb b/app/views/posts/partials/show/_download.html.erb index 399d919b9..b9ad40d0a 100644 --- a/app/views/posts/partials/show/_download.html.erb +++ b/app/views/posts/partials/show/_download.html.erb @@ -1 +1 @@ -
<%= link_to "Save this file (right click and save)", post.file_url %>
+<%= link_to "Save this file (right click and save)", post.tagged_file_url %>
diff --git a/app/views/posts/partials/show/_flash.html.erb b/app/views/posts/partials/show/_flash.html.erb index 8ff9c88c1..a54976ecf 100644 --- a/app/views/posts/partials/show/_flash.html.erb +++ b/app/views/posts/partials/show/_flash.html.erb @@ -1,6 +1,6 @@ <%= content_tag(:object, :width => post.image_width, :height => post.image_height) do %> - <%= tag :params, :name => "movie", :value => post.file_url %> - <%= tag :embed, :src => post.file_url, :width => post.image_width, :height => post.image_height, :allowScriptAccess => "never" %> + <%= tag :params, :name => "movie", :value => post.tagged_file_url %> + <%= tag :embed, :src => post.tagged_file_url, :width => post.image_width, :height => post.image_height, :allowScriptAccess => "never" %> <% end %> -<%= link_to "Save this flash (right click and save)", post.file_url %>
+<%= link_to "Save this flash (right click and save)", post.tagged_file_url %>
diff --git a/app/views/posts/partials/show/_information.html.erb b/app/views/posts/partials/show/_information.html.erb index 078d30987..4b0658a58 100644 --- a/app/views/posts/partials/show/_information.html.erb +++ b/app/views/posts/partials/show/_information.html.erb @@ -12,7 +12,7 @@<% if post.has_ugoira_webm? %> - <%= link_to "Save as video (right click and save)", post.large_file_url %> + <%= link_to "Save as video (right click and save)", post.tagged_large_file_url %> <% else %> WebM conversion pending <% end %> diff --git a/app/views/posts/partials/show/_ugoira_webm.html.erb b/app/views/posts/partials/show/_ugoira_webm.html.erb index a30c8b7d7..3e8e48401 100644 --- a/app/views/posts/partials/show/_ugoira_webm.html.erb +++ b/app/views/posts/partials/show/_ugoira_webm.html.erb @@ -1,3 +1,3 @@ -<%= content_tag(:video, nil, :id => "image", :width => post.image_width, :height => post.image_height, :autoplay => true, :loop => true, :controls => "controls", :src => post.large_file_url) %> +<%= content_tag(:video, nil, :id => "image", :width => post.image_width, :height => post.image_height, :autoplay => true, :loop => true, :controls => "controls", :src => post.tagged_large_file_url) %> -
<%= link_to "Save this video (right click and save)", post.large_file_url %> | <%= link_to "View original", post_path(post, :original => 1) %>
+<%= link_to "Save this video (right click and save)", post.tagged_large_file_url %> | <%= link_to "View original", post_path(post, :original => 1) %>
diff --git a/app/views/posts/partials/show/_video.html.erb b/app/views/posts/partials/show/_video.html.erb index ea7e55872..f53c01b00 100644 --- a/app/views/posts/partials/show/_video.html.erb +++ b/app/views/posts/partials/show/_video.html.erb @@ -1,3 +1,3 @@ -<%= content_tag(:video, nil, :id => "image", :width => post.image_width, :height => post.image_height, :autoplay => true, :loop => !post.has_tag?("video_with_sound"), :controls => "controls", :src => post.file_url) %> +<%= content_tag(:video, nil, :id => "image", :width => post.image_width, :height => post.image_height, :autoplay => true, :loop => !post.has_tag?("video_with_sound"), :controls => "controls", :src => post.tagged_file_url) %> -<%= link_to "Save this video (right click and save)", post.file_url %>
+<%= link_to "Save this video (right click and save)", post.tagged_file_url %>