From 24208a654fe65a2016244f0ebb99af66ed0bd8d7 Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 18 Feb 2013 12:13:30 +0100 Subject: received fax documents --- app/models/fax_document.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'app/models/fax_document.rb') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index 564d3bb..a0d2100 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -68,6 +68,29 @@ class FaxDocument < ActiveRecord::Base FileUtils.rm_rf tmp_dir end + def tiff_to_pdf() + tiff_file = self.tiff.to_s.gsub(self.tiff.store_path, '') + if !File.exists?(tiff_file) + return nil + end + + working_path, file_name = File.split(tiff_file) + pdf_file = "#{working_path}/#{File.basename(tiff_file, '.tiff')}.pdf" + + system "tiff2pdf \\ + -o \"#{pdf_file}\" \\ + -p letter \\ + -a \"#{self.remote_station_id}\" \\ + -c \"AMOOMA Gemeinschaft version #{GsParameter.get('GEMEINSCHAFT_VERSION')}\" \\ + -t \"#{self.remote_station_id}\" \"#{tiff_file}\"" + + if !File.exists?(pdf_file) + return nil + end + + return pdf_file, tiff_file + end + private def convert_pdf_to_tiff page_size_a4 = '595 842' -- cgit v1.2.3 From 99af7fc0788735bec2a450ca0fa3e264ea9625c1 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Mon, 18 Feb 2013 13:14:16 +0100 Subject: use /var/spool/gemeinschaft as spooling dir --- app/models/fax_document.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models/fax_document.rb') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index 564d3bb..2e37998 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -57,7 +57,7 @@ class FaxDocument < ActiveRecord::Base end def create_thumbnails_and_save_them - tmp_dir = "/tmp/fax_convertions/#{self.id}" + tmp_dir = "/var/spool/gemeinschaft/fax_convertions/#{self.id}" FileUtils.mkdir_p tmp_dir system("cd #{tmp_dir} && convert #{self.document.path} -colorspace Gray PNG:'fax_page.png'") Dir.glob("#{tmp_dir}/fax_page*.png").each do |thumbnail| @@ -72,7 +72,7 @@ class FaxDocument < ActiveRecord::Base def convert_pdf_to_tiff page_size_a4 = '595 842' page_size_command = "<< /Policies << /PageSize 3 >> /InputAttributes currentpagedevice /InputAttributes get dup { pop 1 index exch undef } forall dup 0 << /PageSize [ #{page_size_a4} ] >> put >> setpagedevice" - directory = "/tmp/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/faxes/#{self.id}" + directory = "/var/spool/gemeinschaft/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/faxes/#{self.id}" FileUtils.mkdir_p directory tiff_file_name = File.basename(self.document.to_s.downcase, ".pdf") + '.tiff' system "cd #{directory} && gs -q -r#{self.fax_resolution.resolution_value} -dNOPAUSE -dBATCH -dSAFER -sDEVICE=tiffg3 -sOutputFile=\"#{tiff_file_name}\" -c \"#{page_size_command}\" -- \"#{Rails.root.to_s}/public#{self.document.to_s}\"" -- cgit v1.2.3 From 2b3892ac24bb61c4814e0afe141bf53765fb1e4b Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 19 Feb 2013 13:16:12 +0100 Subject: fax storage directory --- app/models/fax_document.rb | 55 ++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'app/models/fax_document.rb') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index c73fa3d..e9bb5f1 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -1,8 +1,7 @@ class FaxDocument < ActiveRecord::Base # attr_accessible :inbound, :transmission_time, :sent_at, :document_total_pages, :document_transferred_pages, :ecm_requested, :ecm_used, :image_resolution, :image_size, :local_station_id, :result_code, :result_text, :remote_station_id, :success, :transfer_rate, :t38_gateway_format, :t38_peer, :document - mount_uploader :document, DocumentUploader - mount_uploader :tiff, TiffUploader + mount_uploader :document, FaxDocumentUploader validates_presence_of :document validates_numericality_of :retry_counter, :only_integer => true, :greater_than_or_equal_to => 0 @@ -18,7 +17,7 @@ class FaxDocument < ActiveRecord::Base has_many :fax_thumbnails, :order => :position, :dependent => :destroy - after_create :convert_pdf_to_tiff + after_save :convert_to_tiff after_create :render_thumbnails # Scopes @@ -68,40 +67,58 @@ class FaxDocument < ActiveRecord::Base FileUtils.rm_rf tmp_dir end - def tiff_to_pdf() - tiff_file = self.tiff.to_s.gsub(self.tiff.store_path, '') - if !File.exists?(tiff_file) + def tiff_to_pdf + if !File.exists?(self.tiff) return nil end - working_path, file_name = File.split(tiff_file) - pdf_file = "#{working_path}/#{File.basename(tiff_file, '.tiff')}.pdf" + working_path, file_name = File.split(self.tiff) + pdf_file = "#{working_path}/#{File.basename(self.tiff, '.tiff')}.pdf" system "tiff2pdf \\ -o \"#{pdf_file}\" \\ -p letter \\ -a \"#{self.remote_station_id}\" \\ -c \"AMOOMA Gemeinschaft version #{GsParameter.get('GEMEINSCHAFT_VERSION')}\" \\ - -t \"#{self.remote_station_id}\" \"#{tiff_file}\"" + -t \"#{self.remote_station_id}\" \"#{self.tiff}\"" if !File.exists?(pdf_file) return nil end - return pdf_file, tiff_file + return pdf_file end - private - def convert_pdf_to_tiff + def to_tiff page_size_a4 = '595 842' page_size_command = "<< /Policies << /PageSize 3 >> /InputAttributes currentpagedevice /InputAttributes get dup { pop 1 index exch undef } forall dup 0 << /PageSize [ #{page_size_a4} ] >> put >> setpagedevice" - directory = "/var/spool/gemeinschaft/GS-#{GsParameter.get('GEMEINSCHAFT_VERSION')}/faxes/#{self.id}" - FileUtils.mkdir_p directory - tiff_file_name = File.basename(self.document.to_s.downcase, ".pdf") + '.tiff' - system "cd #{directory} && gs -q -r#{self.fax_resolution.resolution_value} -dNOPAUSE -dBATCH -dSAFER -sDEVICE=tiffg3 -sOutputFile=\"#{tiff_file_name}\" -c \"#{page_size_command}\" -- \"#{Rails.root.to_s}/public#{self.document.to_s}\"" - self.tiff = File.open("#{directory}/#{tiff_file_name}") - self.save - FileUtils.rm_rf directory + working_path, file_name = File.split(self.document.to_s) + tiff_file = File.basename(file_name.to_s.downcase, File.extname(file_name)) + '.tiff' + result = system "cd #{store_dir} && gs -q -r#{self.fax_resolution.resolution_value} -dNOPAUSE -dBATCH -dSAFER -sDEVICE=tiffg3 -sOutputFile=\"#{tiff_file}\" -c \"#{page_size_command}\" -- \"#{self.document.to_s}\"" + + if !File.exists?("#{store_dir}/#{tiff_file}") + return nil + end + + return "#{store_dir}/#{tiff_file}" + end + + def store_dir + if self.try(:inbound) + "/var/opt/gemeinschaft/fax/in/#{self.id}" + else + "/var/opt/gemeinschaft/fax/out/#{self.id}" + end + end + + private + def convert_to_tiff + if self.tiff.blank? + self.tiff = self.to_tiff + if self.tiff + return self.save + end + end end end -- cgit v1.2.3 From 22d581aa38ae4e015c654356fb61d110456e69ee Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 19 Feb 2013 14:05:11 +0100 Subject: preserve tiff file --- app/models/fax_document.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'app/models/fax_document.rb') diff --git a/app/models/fax_document.rb b/app/models/fax_document.rb index e9bb5f1..5b27965 100644 --- a/app/models/fax_document.rb +++ b/app/models/fax_document.rb @@ -19,6 +19,8 @@ class FaxDocument < ActiveRecord::Base after_save :convert_to_tiff after_create :render_thumbnails + + after_destroy :remove_storage_dir # Scopes scope :inbound, where(:state => 'inbound') @@ -105,9 +107,9 @@ class FaxDocument < ActiveRecord::Base def store_dir if self.try(:inbound) - "/var/opt/gemeinschaft/fax/in/#{self.id}" + "/var/opt/gemeinschaft/fax/in/#{self.id.to_i}" else - "/var/opt/gemeinschaft/fax/out/#{self.id}" + "/var/opt/gemeinschaft/fax/out/#{self.id.to_i}" end end @@ -121,4 +123,10 @@ class FaxDocument < ActiveRecord::Base end end + def remove_storage_dir + if File.directory?(self.store_dir) + FileUtils.rm_rf(self.store_dir) + end + end + end -- cgit v1.2.3