diff options
author | Louise Crow <louise.crow@gmail.com> | 2012-08-01 15:22:32 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2012-08-01 15:22:32 +0100 |
commit | c9d8f483e727734a7f0afad9871df516e8c0470c (patch) | |
tree | f706fcc00cd82c69b90019dd00606905c7a83d43 /app/models | |
parent | 48c4c19c64c719af8d23c9d46111539b9d447b6d (diff) | |
parent | 1df6f6bfaf51c71c40bca4228cf3db5006306694 (diff) |
Merge remote-tracking branch 'origin/develop' into develop
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/foi_attachment.rb | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index 9bbf0988f..a40898aef 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -1,3 +1,5 @@ +# encoding: UTF-8 + # == Schema Information # Schema version: 114 # @@ -14,8 +16,6 @@ # hexdigest :string(32) # -# encoding: UTF-8 - # models/foi_attachment.rb: # An attachment to an email (IncomingMessage) # @@ -315,14 +315,21 @@ class FoiAttachment < ActiveRecord::Base tempfile.print self.body tempfile.flush + html = nil if self.content_type == 'application/pdf' - html = AlaveteliExternalCommand.run("pdftohtml", "-nodrm", "-zoom", "1.0", "-stdout", "-enc", "UTF-8", "-noframes", tempfile.path) + # We set a timeout here, because pdftohtml can spiral out of control + # on some PDF files and we don’t want to crash the whole server. + html = AlaveteliExternalCommand.run("pdftohtml", "-nodrm", "-zoom", "1.0", "-stdout", "-enc", "UTF-8", "-noframes", tempfile.path, :timeout => 30) elsif self.content_type == 'application/rtf' - html = AlaveteliExternalCommand.run("unrtf", "--html", tempfile.path) - elsif self.has_google_docs_viewer? - html = '' # force error and using Google docs viewer - else - raise "No HTML conversion available for type " + self.content_type + html = AlaveteliExternalCommand.run("unrtf", "--html", tempfile.path, :timeout => 120) + end + + if html.nil? + if self.has_google_docs_viewer? + html = '' # force error and using Google docs viewer + else + raise "No HTML conversion available for type " + self.content_type + end end tempfile.close |