mirror of https://github.com/tootsuite/mastodon
Show multibyte URI preview card (#2363)
parent
57cd6546c3
commit
d670f72830
|
@ -1,11 +1,12 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class FetchLinkCardService < BaseService
|
class FetchLinkCardService < BaseService
|
||||||
|
URL_PATTERN = %r{https?://\S+}
|
||||||
USER_AGENT = "#{HTTP::Request::USER_AGENT} (Mastodon/#{Mastodon::VERSION}; +http://#{Rails.configuration.x.local_domain}/)"
|
USER_AGENT = "#{HTTP::Request::USER_AGENT} (Mastodon/#{Mastodon::VERSION}; +http://#{Rails.configuration.x.local_domain}/)"
|
||||||
|
|
||||||
def call(status)
|
def call(status)
|
||||||
# Get first http/https URL that isn't local
|
# Get first http/https URL that isn't local
|
||||||
url = URI.extract(status.text).reject { |uri| (uri =~ /\Ahttps?:\/\//).nil? || TagManager.instance.local_url?(uri) }.first
|
url = status.text.match(URL_PATTERN).to_a.reject { |uri| TagManager.instance.local_url?(uri) }.first
|
||||||
|
|
||||||
return if url.nil?
|
return if url.nil?
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue