commit
c26a375e2b
@ -0,0 +1,12 @@
|
|||||||
|
#coding=utf-8
|
||||||
|
#
|
||||||
|
class OfficeConverTask
|
||||||
|
def conver(source_file, saved_file)
|
||||||
|
office = Trustie::Utils::Office.new(source_file)
|
||||||
|
if office.conver(saved_file)
|
||||||
|
Rails.logger.info "process ok: #{saved_file} "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
handle_asynchronously :conver,:queue => 'office_conver'
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,42 @@
|
|||||||
|
module Trustie
|
||||||
|
module Utils
|
||||||
|
class Office
|
||||||
|
|
||||||
|
def initialize(file)
|
||||||
|
@file = file
|
||||||
|
end
|
||||||
|
|
||||||
|
def office?
|
||||||
|
%w(doc docx ppt pptx xls xlsx pdf).any?{|word| @file.downcase.end_with?(word)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def conver(saved_file, force=false)
|
||||||
|
if force || !File.exist?(saved_file)
|
||||||
|
if File.exist? @file
|
||||||
|
if office?
|
||||||
|
begin
|
||||||
|
resource = RestClient::Resource.new(
|
||||||
|
'http://192.168.80.107/Any2HtmlHandler.ashx',
|
||||||
|
:timeout => -1,
|
||||||
|
:open_timeout => -1
|
||||||
|
)
|
||||||
|
req = resource.post :txtDes => File.new(@file, 'rb')
|
||||||
|
File.new(saved_file, "ab+") do |f|
|
||||||
|
f.write(req.body)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
rescue =>e
|
||||||
|
puts e.message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "can't find file #{@file}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in new issue