]> cat aescling's git repositories - mastodon.git/commitdiff
Fixed duplicating URL of photo type of oEmbed (#5763)
authorabcang <abcang1015@gmail.com>
Mon, 20 Nov 2017 19:45:54 +0000 (04:45 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 20 Nov 2017 19:45:54 +0000 (20:45 +0100)
app/services/fetch_link_card_service.rb

index 14c21b6ccf8274eda18316796296bfaef864daf2..37cf75379f0195a03c09a4976fa2487528cc654b 100644 (file)
@@ -74,6 +74,9 @@ class FetchLinkCardService < BaseService
 
     return false unless response.respond_to?(:type)
 
+    # The photo will change the URL. So, to avoid duplication of URLs, PreviewCard needs to be checked again.
+    @card = PreviewCard.find_by(url: response.url) || @card if response.type == 'photo'
+
     @card.type          = response.type
     @card.title         = response.respond_to?(:title)         ? response.title         : ''
     @card.author_name   = response.respond_to?(:author_name)   ? response.author_name   : ''