|
|
|
@ -66,6 +66,12 @@ class AttachmentsController < ApplicationController
|
|
|
|
|
file.downcase.end_with?(".pdf")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def direct_download
|
|
|
|
|
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
|
|
|
|
:type => detect_content_type(@attachment),
|
|
|
|
|
:disposition => 'attachment' #inline can open in browser
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def download
|
|
|
|
|
# modify by nwb
|
|
|
|
|
# 下载添加权限设置
|
|
|
|
@ -73,23 +79,30 @@ class AttachmentsController < ApplicationController
|
|
|
|
|
if candown || User.current.admin? || User.current.id == @attachment.author_id
|
|
|
|
|
@attachment.increment_download
|
|
|
|
|
if stale?(:etag => @attachment.digest)
|
|
|
|
|
convered_file = @attachment.diskfile
|
|
|
|
|
unless pdf?(convered_file)
|
|
|
|
|
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
|
|
|
|
|
end
|
|
|
|
|
if File.exist?(convered_file) && pdf?(convered_file)
|
|
|
|
|
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
|
|
|
|
|
if params[:force] == 'true'
|
|
|
|
|
direct_download
|
|
|
|
|
else
|
|
|
|
|
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
|
|
|
|
:type => detect_content_type(@attachment),
|
|
|
|
|
:disposition => 'attachment' #inline can open in browser
|
|
|
|
|
convered_file = @attachment.diskfile
|
|
|
|
|
#如果本身不是pdf文件,则先寻找是不是已转换化,如果没有则转化
|
|
|
|
|
unless pdf?(convered_file)
|
|
|
|
|
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
|
|
|
|
|
unless File.exist?(convered_file)
|
|
|
|
|
office = Trustie::Utils::Office.new(@attachment.diskfile)
|
|
|
|
|
office.conver(convered_file)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if File.exist?(convered_file) && pdf?(convered_file)
|
|
|
|
|
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
|
|
|
|
|
else
|
|
|
|
|
direct_download
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
render_403 :message => :notice_not_authorized
|
|
|
|
|
end
|
|
|
|
|
rescue => e
|
|
|
|
|
redirect_to "http: //" + (Setting.host_name.to_s) +"/file_not_found.html"
|
|
|
|
|
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#更新资源文件类型
|
|
|
|
|