diff options
author | spag <spag@golwen.net> | 2013-02-18 12:13:30 +0100 |
---|---|---|
committer | spag <spag@golwen.net> | 2013-02-18 12:13:30 +0100 |
commit | 24208a654fe65a2016244f0ebb99af66ed0bd8d7 (patch) | |
tree | 46072a6ed862326ebcf610ea1cfbd9e4145b33ed /app | |
parent | 45855989c9f1b9122d57f3328102730b49236432 (diff) |
received fax documents
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/trigger_controller.rb | 31 | ||||
-rw-r--r-- | app/models/fax_document.rb | 23 |
2 files changed, 29 insertions, 25 deletions
diff --git a/app/controllers/trigger_controller.rb b/app/controllers/trigger_controller.rb index 9a03979..7840498 100644 --- a/app/controllers/trigger_controller.rb +++ b/app/controllers/trigger_controller.rb @@ -1,7 +1,4 @@ class TriggerController < ApplicationController - TIFF_FUFFIX = ".tiff" - PDF_SUFFIX = ".pdf" - TMP_DIR = "/var/spool/freeswitch/" def voicemail if !params[:sip_account_id].blank? @@ -68,25 +65,9 @@ class TriggerController < ApplicationController if fax_account fax_account.fax_documents.where(:state => 'received').each do |fax_document| - tiff_file = File.basename(fax_document.tiff.to_s) + pdf_file, tiff_file = fax_document.tiff_to_pdf.blank? - if !File.exists?( "#{TMP_DIR}#{tiff_file}" ) - fax_document.state = 'unsuccessful' - fax_document.save - next - end - - paper_size = "letter" - pdf_file = "#{TMP_DIR}#{File.basename(tiff_file, TIFF_FUFFIX)}#{PDF_SUFFIX}" - - system "tiff2pdf \\ - -o \"#{pdf_file}\" \\ - -p #{paper_size} \\ - -a \"#{fax_document.remote_station_id}\" \\ - -c \"AMOOMA Gemeinschaft version #{GsParameter.get('GEMEINSCHAFT_VERSION')}\" \\ - -t \"#{fax_document.remote_station_id}\" \"#{TMP_DIR}#{tiff_file}\"" - - if !File.exists?( pdf_file ) + if !pdf_file fax_document.state = 'unsuccessful' fax_document.save next @@ -98,14 +79,14 @@ class TriggerController < ApplicationController if fax_document.save Notifications.new_fax(fax_document).deliver begin - File.delete("#{TMP_DIR}#{tiff_file}"); + File.delete(tiff_file) rescue => e - logger.error "Raw fax file could not be deleted: #{TMP_DIR}#{tiff_file} => #{e.inspect}" + logger.error "Raw fax file could not be deleted: #{tiff_file} => #{e.inspect}" end begin - File.delete(pdf_file); + File.delete(pdf_file) rescue => e - logger.error "PDF fax file could not be deleted: #{TMP_DIR}#{pdf_file} => #{e.inspect}" + logger.error "PDF fax file could not be deleted: #{pdf_file} => #{e.inspect}" end fax_document.tiff = nil fax_document.save 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' |