|
|
|
@ -62,6 +62,10 @@ class AttachmentsController < ApplicationController
|
|
|
|
|
render :action => 'file'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pdf?(file)
|
|
|
|
|
file.downcase.end_with?(".pdf")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def download
|
|
|
|
|
# modify by nwb
|
|
|
|
|
# 下载添加权限设置
|
|
|
|
@ -69,9 +73,12 @@ class AttachmentsController < ApplicationController
|
|
|
|
|
if candown || User.current.admin? || User.current.id == @attachment.author_id
|
|
|
|
|
@attachment.increment_download
|
|
|
|
|
if stale?(:etag => @attachment.digest)
|
|
|
|
|
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".html")
|
|
|
|
|
if File.exist?(convered_file)
|
|
|
|
|
send_file convered_file, :type => 'text/html; charset=utf-8', :disposition => 'inline'
|
|
|
|
|
convered_file = @attachment.disk_filename
|
|
|
|
|
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'
|
|
|
|
|
else
|
|
|
|
|
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
|
|
|
|
:type => detect_content_type(@attachment),
|
|
|
|
|