mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:11:08 +08:00
FEATURE: Onebox can match engines based on the content_type (#13876)
* FEATURE: Onebox can match engines based on the content_type `FinalDestination` now returns the `content_type` of a resolved URL. `Oneboxer` passes this value to `Onebox` itself. Onebox engines can now specify a `matches_content_type` regex of content_types that the engine can handle, regardless of the URL. `ImageOnebox` will match URLs with a content type of `image/png`, `jpg`, `gif`, `bmp`, `tif`, etc. This will allow images that exist at a URL without a file type extension to be correctly rendered, assuming a valid `content_type` is returned.
This commit is contained in:
@ -96,6 +96,12 @@ module Onebox
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def handles_content_type?(other)
|
||||
if other && class_variable_defined?(:@@matcher_content_type)
|
||||
!!(other.to_s =~ class_variable_get(:@@matcher_content_type))
|
||||
end
|
||||
end
|
||||
|
||||
def ===(other)
|
||||
if other.kind_of?(URI)
|
||||
!!(other.to_s =~ class_variable_get(:@@matcher))
|
||||
@ -112,6 +118,10 @@ module Onebox
|
||||
class_variable_set :@@matcher, r
|
||||
end
|
||||
|
||||
def matches_content_type(ct)
|
||||
class_variable_set :@@matcher_content_type, ct
|
||||
end
|
||||
|
||||
def requires_iframe_origins(*origins)
|
||||
class_variable_set :@@iframe_origins, origins
|
||||
end
|
||||
|
Reference in New Issue
Block a user