From c6e54e202ae15dff12e7fc2c6645e10a175075c3 Mon Sep 17 00:00:00 2001 From: bohung Date: Sun, 17 May 2020 21:30:39 +0800 Subject: [PATCH] Fix accessibility. --- .../stylesheets/archive/download_file.css | 16 +++++++++++++ app/controllers/archives_controller.rb | 23 +++++++++++++++---- app/views/archives/download_file.html.erb | 11 +++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 app/assets/stylesheets/archive/download_file.css create mode 100644 app/views/archives/download_file.html.erb diff --git a/app/assets/stylesheets/archive/download_file.css b/app/assets/stylesheets/archive/download_file.css new file mode 100644 index 0000000..f917370 --- /dev/null +++ b/app/assets/stylesheets/archive/download_file.css @@ -0,0 +1,16 @@ +body{ + margin: 0px; + background: #0e0e0e; +} +img{ + -webkit-user-select: none; + margin: auto; + display: block; + position: absolute; + left: 50%; + top: 50%; + transform: translate(-50%, -50%); +} +h3{ + display: none; +} \ No newline at end of file diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index d3fed76..57492c1 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -188,11 +188,24 @@ class ArchivesController < ApplicationController file_id = params[:file] file = ArchiveFileMultiple.find(file_id) rescue nil if !file.nil? - file.download_count = file.download_count + 1 - file.save - redirect_to file.file.url and return - end - render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found + file.download_count = file.download_count + 1 + file.save + @url = file.file.url + begin + @path = file.file.file.file rescue "" + @filename = @path.split("/").last + @ext = @path.split("/").last.to_s.split(".").last + if @ext == "png" || @ext == "jpg" || @ext == "bmp" + render "download_file",:layout=>false + else + send_file(@path) + end + rescue + redirect_to @url + end + else + render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found + end end def group_by_category diff --git a/app/views/archives/download_file.html.erb b/app/views/archives/download_file.html.erb new file mode 100644 index 0000000..1bbee7f --- /dev/null +++ b/app/views/archives/download_file.html.erb @@ -0,0 +1,11 @@ + + + + <%=@filename%> + + + +

<%=@filename%>

+ <%=@filename%> + +> \ No newline at end of file