|
|
|
@ -74,6 +74,45 @@ class AttachmentsController < ApplicationController
|
|
|
|
|
:disposition => 'attachment' #inline can open in browser
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def direct_download_history
|
|
|
|
|
@attachment_history = AttachmentHistory.find(params[:id])
|
|
|
|
|
@attachment_history.increment_download
|
|
|
|
|
send_file @attachment_history.diskfile_history, :filename => filename_for_content_disposition(@attachment_history.filename),
|
|
|
|
|
:type => detect_content_type(@attachment_history),
|
|
|
|
|
:disposition => 'attachment' #inline can open in browser
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def download_history
|
|
|
|
|
@attachment_history = AttachmentHistory.find(params[:id])
|
|
|
|
|
candown = attachment_history_candown @attachment_history
|
|
|
|
|
if candown || User.current.admin? || User.current.id == @attachment_history.author_id
|
|
|
|
|
if stale?(:etag => @attachment_history.digest)
|
|
|
|
|
if params[:preview] == 'true'
|
|
|
|
|
convered_file = @attachment_history.diskfile_history
|
|
|
|
|
#如果本身不是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_history.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_history
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
direct_download_history
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
render_403 :message => :notice_not_authorized
|
|
|
|
|
end
|
|
|
|
|
rescue => e
|
|
|
|
|
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def download
|
|
|
|
|
# modify by nwb
|
|
|
|
|
# 下载添加权限设置
|
|
|
|
@ -212,7 +251,7 @@ class AttachmentsController < ApplicationController
|
|
|
|
|
@history.version = @old_history.nil? ? 1 : @old_history.version + 1
|
|
|
|
|
@history.save #历史记录保存完毕
|
|
|
|
|
#将最新保存的记录 数据替换到 需要修改的文件记录
|
|
|
|
|
@old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public")
|
|
|
|
|
@old_attachment.attributes = @attachment.attributes.dup.except("id","container_id","container_type","is_public","downloads")
|
|
|
|
|
@old_attachment.save
|
|
|
|
|
#删除当前记录
|
|
|
|
|
@attachment.delete
|
|
|
|
|