mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-15 03:15:32 +00:00
6a4e2db661
* Raise an error for remote url in StatusFinder Previous implementation had allowed remote url with status id which also exists on local. Then that bug leads /api/web/embed to return wrong embed url. * Fix oembed_controller_spec
37 lines
696 B
Ruby
37 lines
696 B
Ruby
# frozen_string_literal: true
|
|
|
|
class StatusFinder
|
|
attr_reader :url
|
|
|
|
def initialize(url)
|
|
@url = url
|
|
end
|
|
|
|
def status
|
|
verify_action!
|
|
|
|
raise ActiveRecord::RecordNotFound unless TagManager.instance.local_url?(url)
|
|
|
|
case recognized_params[:controller]
|
|
when 'stream_entries'
|
|
StreamEntry.find(recognized_params[:id]).status
|
|
when 'statuses'
|
|
Status.find(recognized_params[:id])
|
|
else
|
|
raise ActiveRecord::RecordNotFound
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def recognized_params
|
|
Rails.application.routes.recognize_path(url)
|
|
end
|
|
|
|
def verify_action!
|
|
unless recognized_params[:action] == 'show'
|
|
raise ActiveRecord::RecordNotFound
|
|
end
|
|
end
|
|
end
|