1
0
Fork 0
forked from gitea/nas

Add: #667 プレビューカード、参照のフェッチを行わないドメインの設定 (#690)

This commit is contained in:
KMY(雪あすか) 2024-04-03 12:37:18 +09:00 committed by GitHub
parent ff2860d0df
commit d89e1114bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 123 additions and 2 deletions

View file

@ -0,0 +1,34 @@
# frozen_string_literal: true
module Admin
class SpecialDomainsController < BaseController
def show
authorize :instance, :show?
@admin_settings = Form::AdminSettings.new
end
def create
authorize :instance, :destroy?
@admin_settings = Form::AdminSettings.new(settings_params)
if @admin_settings.save
flash[:notice] = I18n.t('generic.changes_saved_msg')
redirect_to after_update_redirect_path
else
render :show
end
end
private
def after_update_redirect_path
admin_special_domains_path
end
def settings_params
params.require(:form_admin_settings).permit(*Form::AdminSettings::KEYS)
end
end
end

View file

@ -63,6 +63,8 @@ class Form::AdminSettings
emoji_reaction_disallow_domains
block_unfollow_account_mention
hold_remote_new_accounts
stop_fetch_activity_domains
stop_link_preview_domains
).freeze
INTEGER_KEYS = %i(
@ -120,6 +122,8 @@ class Form::AdminSettings
STRING_ARRAY_KEYS = %i(
emoji_reaction_disallow_domains
stop_fetch_activity_domains
stop_link_preview_domains
).freeze
attr_accessor(*KEYS)

View file

@ -106,7 +106,8 @@ class FetchLinkCardService < BaseService
def bad_url?(uri)
# Avoid local instance URLs and invalid URLs
uri.host.blank? || TagManager.instance.local_url?(uri.to_s) || !%w(http https).include?(uri.scheme)
uri.host.blank? || TagManager.instance.local_url?(uri.to_s) || !%w(http https).include?(uri.scheme) ||
referenced_urls.include?(uri.to_s) || Setting.stop_link_preview_domains&.include?(uri.host)
end
def mention_link?(anchor)

View file

@ -153,10 +153,16 @@ class ProcessReferencesService < BaseService
def url_to_status(url)
status = ActivityPub::TagManager.instance.uri_to_resource(url, Status, url: true)
status ||= ResolveURLService.new.call(url, on_behalf_of: @status.account) if @fetch_remote && @no_fetch_urls.exclude?(url)
status ||= ResolveURLService.new.call(url, on_behalf_of: @status.account) unless bad_url_to_fetch?(url)
referrable?(status) ? status : nil
end
def bad_url_to_fetch?(url)
uri = Addressable::URI.parse(url).normalize
!@fetch_remote || @no_fetch_urls.include?(url) || uri.host.blank? || Setting.stop_fetch_activity_domains&.include?(uri.host)
end
def referrable?(target_status)
return false if target_status.nil?
return @referrable if defined?(@referrable)

View file

@ -0,0 +1,17 @@
- content_for :page_title do
= t('admin.special_domains.title')
- content_for :header_tags do
= javascript_pack_tag 'admin', async: true, crossorigin: 'anonymous'
= simple_form_for @admin_settings, url: admin_special_domains_path, html: { method: :post } do |f|
= render 'shared/error_messages', object: @admin_settings
.fields-group
= f.input :stop_fetch_activity_domains, wrapper: :with_label, as: :text, input_html: { rows: 6 }, label: t('admin.special_domains.stop_fetch_activity_domains.title'), hint: t('admin.special_domains.stop_fetch_activity_domains.preamble')
.fields-group
= f.input :stop_link_preview_domains, wrapper: :with_label, as: :text, input_html: { rows: 6 }, label: t('admin.special_domains.stop_link_preview_domains.title'), hint: t('admin.special_domains.stop_link_preview_domains.preamble')
.actions
= f.button :button, t('generic.save_changes'), type: :submit