转换变为既时转换

redis_cache
guange 10 years ago
parent d3baada893
commit 444658d0b3

@ -66,6 +66,12 @@ class AttachmentsController < ApplicationController
file.downcase.end_with?(".pdf") file.downcase.end_with?(".pdf")
end 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 def download
# modify by nwb # modify by nwb
# 下载添加权限设置 # 下载添加权限设置
@ -73,23 +79,30 @@ class AttachmentsController < ApplicationController
if candown || User.current.admin? || User.current.id == @attachment.author_id if candown || User.current.admin? || User.current.id == @attachment.author_id
@attachment.increment_download @attachment.increment_download
if stale?(:etag => @attachment.digest) if stale?(:etag => @attachment.digest)
convered_file = @attachment.diskfile if params[:force] == 'true'
unless pdf?(convered_file) direct_download
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 else
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename), convered_file = @attachment.diskfile
:type => detect_content_type(@attachment), #如果本身不是pdf文件则先寻找是不是已转换化如果没有则转化
:disposition => 'attachment' #inline can open in browser 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
end end
else else
render_403 :message => :notice_not_authorized render_403 :message => :notice_not_authorized
end end
rescue => e 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 end
#更新资源文件类型 #更新资源文件类型

@ -259,13 +259,14 @@ class Attachment < ActiveRecord::Base
end end
def office_conver def office_conver
return unless %w(Project Course).include? (self.container_type) # 不在这里做后台转换,换为点击时做转换
saved_path = File.join(Rails.root, "files", "convered_office") # return unless %w(Project Course).include? (self.container_type)
unless Dir.exist?(saved_path) # saved_path = File.join(Rails.root, "files", "convered_office")
Dir.mkdir(saved_path) # unless Dir.exist?(saved_path)
end # Dir.mkdir(saved_path)
convered_file = File.join(saved_path, self.disk_filename + ".pdf") # end
OfficeConverTask.new.conver(self.diskfile, convered_file) # convered_file = File.join(saved_path, self.disk_filename + ".pdf")
# OfficeConverTask.new.conver(self.diskfile, convered_file)
end end
# Copies the temporary file to its final location # Copies the temporary file to its final location

@ -30,6 +30,7 @@
<% else %> <% else %>
<%= link_to(l(:label_slected_to_project),quote_resource_show_project_project_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %> <%= link_to(l(:label_slected_to_project),quote_resource_show_project_project_file_path(project,file),:class => "f_l re_select",:remote => true) if has_project?(User.current,file) %>
<% end %> <% end %>
<%= link_to '下载',download_named_attachment_path(file.id, file.filename, force: true),class: 'f_l re_open' %>
<% end %> <% end %>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
@ -37,7 +38,7 @@
<p class="f_l c_grey02 font">文件大小:<%= number_to_human_size(file.filesize) %></p> <p class="f_l c_grey02 font">文件大小:<%= number_to_human_size(file.filesize) %></p>
<%= link_to( l(:button_delete), attachment_path(file), <%= link_to( l(:button_delete), attachment_path(file),
:data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if manage_allowed && file.container_id == project.id && file.container_type == "Project"%> :data => {:confirm => l(:text_are_you_sure)}, :method => :delete,:class => "f_r re_de") if manage_allowed && file.container_id == project.id && file.container_type == "Project"%>
<p class="f_r c_grey02" ><%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>&nbsp;&nbsp;|&nbsp;&nbsp;下载<%= file.downloads %>&nbsp;&nbsp;|&nbsp;&nbsp;引用<%= file.quotes.nil? ? 0:file.quotes %> </p> <p class="f_r c_grey02" ><%= time_tag(file.created_on).html_safe %><%= l(:label_bids_published_ago) %>&nbsp;&nbsp;|&nbsp;&nbsp;下载<%= file.downloads %>&nbsp;&nbsp;|&nbsp;&nbsp;引用<%= file.quotes.nil? ? 0:file.quotes %> </p>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
<div class="tag_h"> <div class="tag_h">
@ -51,4 +52,4 @@
<ul class="wlist"> <ul class="wlist">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => @is_remote, :flag => true%> <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => @is_remote, :flag => true%>
</ul> </ul>
<div class="cl"></div> <div class="cl"></div>

@ -17,12 +17,13 @@ module Trustie
if File.exist? @file if File.exist? @file
if office? if office?
begin begin
resource = RestClient::Resource.new( # resource = RestClient::Resource.new(
'http://192.168.80.107/Any2HtmlHandler.ashx', # 'http://192.168.80.107/Any2HtmlHandler.ashx',
:timeout => -1, # :timeout => -1,
:open_timeout => -1 # :open_timeout => -1
) # )
req = resource.post :txtDes => File.new(@file, 'rb') # req = resource.post :txtDes => File.new(@file, 'rb')
req = RestClient.post 'http://192.168.80.107/Any2HtmlHandler.ashx',:txtDes => File.new(@file, 'rb')
File.delete(saved_file) if File.exist?(saved_file) File.delete(saved_file) if File.exist?(saved_file)
if req.body.length > 10 && !req.body.eql?('转换出错') if req.body.length > 10 && !req.body.eql?('转换出错')
File.open(saved_file, "wb+") do |f| File.open(saved_file, "wb+") do |f|

Loading…
Cancel
Save