839f893168
* Change public accounts pages to mount the web UI * Fix handling of remote usernames in routes - When logged in, serve web app - When logged out, redirect to permalink - Fix `app-body` class not being set sometimes due to name conflict * Fix missing `multiColumn` prop * Fix failing test * Use `discoverable` attribute to control indexing directives * Fix `<ColumnLoading />` not using `multiColumn` * Add `noindex` to accounts in REST API * Change noindex directive to not be rendered by default before a route is mounted * Add loading indicator for detailed status in web UI * Fix missing indicator appearing while account is loading in web UI
45 Zeilen
1,4 KiB
Ruby
45 Zeilen
1,4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class PermalinkRedirector
|
|
include RoutingHelper
|
|
|
|
def initialize(path)
|
|
@path = path
|
|
end
|
|
|
|
def redirect_path
|
|
if path_segments[0].present? && path_segments[0].start_with?('@') && path_segments[1] =~ /\d/
|
|
find_status_url_by_id(path_segments[1])
|
|
elsif path_segments[0].present? && path_segments[0].start_with?('@')
|
|
find_account_url_by_name(path_segments[0])
|
|
elsif path_segments[0] == 'statuses' && path_segments[1] =~ /\d/
|
|
find_status_url_by_id(path_segments[1])
|
|
elsif path_segments[0] == 'accounts' && path_segments[1] =~ /\d/
|
|
find_account_url_by_id(path_segments[1])
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def path_segments
|
|
@path_segments ||= @path.gsub(/\A\//, '').split('/')
|
|
end
|
|
|
|
def find_status_url_by_id(id)
|
|
status = Status.find_by(id: id)
|
|
ActivityPub::TagManager.instance.url_for(status) if status&.distributable? && !status.account.local?
|
|
end
|
|
|
|
def find_account_url_by_id(id)
|
|
account = Account.find_by(id: id)
|
|
ActivityPub::TagManager.instance.url_for(account) if account.present? && !account.local?
|
|
end
|
|
|
|
def find_account_url_by_name(name)
|
|
username, domain = name.gsub(/\A@/, '').split('@')
|
|
domain = nil if TagManager.instance.local_domain?(domain)
|
|
account = Account.find_remote(username, domain)
|
|
|
|
ActivityPub::TagManager.instance.url_for(account) if account.present? && !account.local?
|
|
end
|
|
end
|