mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
BUGFIX: protect ourselved against rogue onebox gem
This commit is contained in:
parent
efaa066a17
commit
239bcd19df
@ -22,24 +22,25 @@ module Oneboxer
|
|||||||
def self.preview(url, options=nil)
|
def self.preview(url, options=nil)
|
||||||
options ||= {}
|
options ||= {}
|
||||||
Oneboxer.invalidate(url) if options[:invalidate_oneboxes]
|
Oneboxer.invalidate(url) if options[:invalidate_oneboxes]
|
||||||
onebox_raw(url).placeholder_html
|
onebox_raw(url)[:preview]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.onebox(url, options=nil)
|
def self.onebox(url, options=nil)
|
||||||
options ||= {}
|
options ||= {}
|
||||||
Oneboxer.invalidate(url) if options[:invalidate_oneboxes]
|
Oneboxer.invalidate(url) if options[:invalidate_oneboxes]
|
||||||
onebox_raw(url).to_s
|
onebox_raw(url)[:onebox]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cached_onebox(url)
|
def self.cached_onebox(url)
|
||||||
Rails.cache.read(onebox_cache_key(url))
|
if c = Rails.cache.read(onebox_cache_key(url))
|
||||||
.to_s
|
c[:onebox]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cached_preview(url)
|
def self.cached_preview(url)
|
||||||
Rails.cache.read(onebox_cache_key(url))
|
if c = Rails.cache.read(onebox_cache_key(url))
|
||||||
.try(:placeholder_html)
|
c[:preview]
|
||||||
.to_s
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.oneboxer_exists_for_url?(url)
|
def self.oneboxer_exists_for_url?(url)
|
||||||
@ -95,12 +96,20 @@ module Oneboxer
|
|||||||
|
|
||||||
private
|
private
|
||||||
def self.onebox_cache_key(url)
|
def self.onebox_cache_key(url)
|
||||||
"onebox_#{url}"
|
"onebox__#{url}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.onebox_raw(url)
|
def self.onebox_raw(url)
|
||||||
Rails.cache.fetch(onebox_cache_key(url)){
|
Rails.cache.fetch(onebox_cache_key(url)){
|
||||||
Onebox.preview(url, cache: {})
|
begin
|
||||||
|
r = Onebox.preview(url, cache: {})
|
||||||
|
{
|
||||||
|
onebox: r.to_s,
|
||||||
|
preview: r.try(:placeholder_html).to_s
|
||||||
|
}
|
||||||
|
rescue => e
|
||||||
|
Discourse.handle_exception(e, url: url)
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user