about summary refs log tree commit diff
path: root/app/controllers/api
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-02-09 12:56:12 +0100
committerGitHub <noreply@github.com>2020-02-09 12:56:12 +0100
commitd3aaa08730901e7c97c6aeb1ebf56f2a027c78a2 (patch)
tree9fcb99dab28b01e0f85fbe7f27f406f92a031903 /app/controllers/api
parenta2cfe3daaadabfaad71969a44c460bd76b8405ff (diff)
parent432033743c409356bd11e0d7d96f14a3cc82fb77 (diff)
Merge pull request #1280 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/web/embeds_controller.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/app/controllers/api/web/embeds_controller.rb b/app/controllers/api/web/embeds_controller.rb
index 6231733b7..4aa31695c 100644
--- a/app/controllers/api/web/embeds_controller.rb
+++ b/app/controllers/api/web/embeds_controller.rb
@@ -7,15 +7,21 @@ class Api::Web::EmbedsController < Api::Web::BaseController
 
   def create
     status = StatusFinder.new(params[:url]).status
+
+    return not_found if status.hidden?
+
     render json: status, serializer: OEmbedSerializer, width: 400
   rescue ActiveRecord::RecordNotFound
     oembed = FetchOEmbedService.new.call(params[:url])
-    oembed[:html] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED) if oembed[:html].present?
 
-    if oembed
-      render json: oembed
-    else
-      render json: {}, status: :not_found
+    return not_found if oembed.nil?
+
+    begin
+      oembed[:html] = Formatter.instance.sanitize(oembed[:html], Sanitize::Config::MASTODON_OEMBED)
+    rescue ArgumentError
+      return not_found
     end
+
+    render json: oembed
   end
 end