2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-21 01:43:12 +08:00
|
|
|
require "has_errors"
|
|
|
|
|
|
|
|
class Embedding < OpenStruct
|
|
|
|
include HasErrors
|
|
|
|
|
|
|
|
def self.settings
|
2025-01-06 10:01:08 +08:00
|
|
|
posts_and_topics_settings | crawlers_settings
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.posts_and_topics_settings
|
|
|
|
%i[embed_by_username embed_post_limit embed_title_scrubber embed_truncate embed_unlisted]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.crawlers_settings
|
|
|
|
%i[allowed_embed_selectors blocked_embed_selectors allowed_embed_classnames]
|
2015-08-21 01:43:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def base_url
|
|
|
|
Discourse.base_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2019-05-07 09:00:09 +08:00
|
|
|
Embedding.settings.each { |s| SiteSetting.set(s, public_send(s)) }
|
2015-08-21 01:43:12 +08:00
|
|
|
true
|
|
|
|
rescue Discourse::InvalidParameters => p
|
|
|
|
errors.add :base, p.to_s
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def embeddable_hosts
|
|
|
|
EmbeddableHost.all.order(:host)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.find
|
|
|
|
embedding_args = { id: "default" }
|
2019-05-07 09:57:27 +08:00
|
|
|
Embedding.settings.each { |s| embedding_args[s] = SiteSetting.get(s) }
|
2015-08-21 01:43:12 +08:00
|
|
|
Embedding.new(embedding_args)
|
|
|
|
end
|
|
|
|
end
|