2017-08-14 02:53:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class IntentsController < ApplicationController
|
2024-02-06 12:56:22 +00:00
|
|
|
EXPECTED_SCHEME = 'web+mastodon'
|
2019-07-08 10:03:45 +00:00
|
|
|
|
2024-02-06 12:56:22 +00:00
|
|
|
before_action :handle_invalid_uri, unless: :valid_uri?
|
2018-06-09 20:47:50 +00:00
|
|
|
rescue_from Addressable::URI::InvalidURIError, with: :handle_invalid_uri
|
2017-08-14 02:53:31 +00:00
|
|
|
|
2018-06-09 20:47:50 +00:00
|
|
|
def show
|
2024-02-06 12:56:22 +00:00
|
|
|
case uri.host
|
|
|
|
when 'follow'
|
|
|
|
redirect_to authorize_interaction_path(uri: uri.query_values['uri'].delete_prefix('acct:'))
|
|
|
|
when 'share'
|
|
|
|
redirect_to share_path(text: uri.query_values['text'])
|
|
|
|
else
|
|
|
|
handle_invalid_uri
|
2017-08-14 02:53:31 +00:00
|
|
|
end
|
|
|
|
end
|
2018-06-09 20:47:50 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-02-06 12:56:22 +00:00
|
|
|
def valid_uri?
|
|
|
|
uri.present? && uri.scheme == EXPECTED_SCHEME
|
2018-06-09 20:47:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def handle_invalid_uri
|
|
|
|
not_found
|
|
|
|
end
|
|
|
|
|
|
|
|
def uri
|
|
|
|
@uri ||= Addressable::URI.parse(params[:uri])
|
|
|
|
end
|
2017-08-14 02:53:31 +00:00
|
|
|
end
|