1
0

intents_controller.rb 721 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. class IntentsController < ApplicationController
  3. EXPECTED_SCHEME = 'web+mastodon'
  4. before_action :handle_invalid_uri, unless: :valid_uri?
  5. rescue_from Addressable::URI::InvalidURIError, with: :handle_invalid_uri
  6. def show
  7. case uri.host
  8. when 'follow'
  9. redirect_to authorize_interaction_path(uri: uri.query_values['uri'].delete_prefix('acct:'))
  10. when 'share'
  11. redirect_to share_path(text: uri.query_values['text'])
  12. else
  13. handle_invalid_uri
  14. end
  15. end
  16. private
  17. def valid_uri?
  18. uri.present? && uri.scheme == EXPECTED_SCHEME
  19. end
  20. def handle_invalid_uri
  21. not_found
  22. end
  23. def uri
  24. @uri ||= Addressable::URI.parse(params[:uri])
  25. end
  26. end