lib/onebox/engine/pdf_onebox.rb in onebox-2.2.14 vs lib/onebox/engine/pdf_onebox.rb in onebox-2.2.15

- old
+ new

@@ -10,28 +10,20 @@ always_https private def data - pdf_info = get_pdf_info - raise "Unable to read pdf file: #{@url}" if pdf_info.nil? + begin + size = Onebox::Helpers.fetch_content_length(@url) + rescue + raise "Unable to read pdf file: #{@url}" + end - result = { link: link, - title: pdf_info[:name], - filesize: pdf_info[:filesize] - } - result - end - - def get_pdf_info - uri = URI.parse(@url) - size = Onebox::Helpers.fetch_content_length(@url) { + link: link, + title: File.basename(uri.path), filesize: size ? Onebox::Helpers.pretty_filesize(size.to_i) : nil, - name: File.basename(uri.path) } - rescue - nil end end end end