mirror of
https://github.com/discourse/discourse.git
synced 2024-12-21 16:53:57 +08:00
30 lines
593 B
Ruby
30 lines
593 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module Onebox
|
||
|
module Engine
|
||
|
class PdfOnebox
|
||
|
include Engine
|
||
|
include LayoutSupport
|
||
|
|
||
|
matches_regexp(%r{^(https?:)?//.*\.pdf(\?.*)?$}i)
|
||
|
always_https
|
||
|
|
||
|
private
|
||
|
|
||
|
def data
|
||
|
begin
|
||
|
size = Onebox::Helpers.fetch_content_length(@url)
|
||
|
rescue StandardError
|
||
|
raise "Unable to read pdf file: #{@url}"
|
||
|
end
|
||
|
|
||
|
{
|
||
|
link: link,
|
||
|
title: File.basename(uri.path),
|
||
|
filesize: size ? Onebox::Helpers.pretty_filesize(size.to_i) : nil,
|
||
|
}
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|