diff --git a/app/models/communication/website/with_associated_objects.rb b/app/models/communication/website/with_associated_objects.rb index 98565eb68865f1e6334f96030b088e0c3cef9fe2..1e293ed3f3f9c8297d705019ab98a080a7e7d735 100644 --- a/app/models/communication/website/with_associated_objects.rb +++ b/app/models/communication/website/with_associated_objects.rb @@ -21,7 +21,7 @@ module Communication::Website::WithAssociatedObjects has_many :permalinks, class_name: "Communication::Website::Permalink", dependent: :destroy - + has_many :communication_blocks, class_name: "Communication::Block", foreign_key: :communication_website_id @@ -29,6 +29,22 @@ module Communication::Website::WithAssociatedObjects end + def blocks_from_education + Communication::Block.where(about: education_programs).or( + Communication::Block.where(about: education_diplomas) + ) + end + + def blocks_from_research + Communication::Block.where(about: research_papers) + end + + def blocks_from_university + Communication::Block.where(about: connected_people).or( + Communication::Block.where(about: connected_organizations) + ) + end + def education_diplomas has_education_diplomas? ? about.diplomas : Education::Diploma.none end diff --git a/app/models/communication/website/with_security.rb b/app/models/communication/website/with_security.rb index 381c5f2a7d16a33c1a412c885bde275d1d8be6da..9ae03475b1e6d02fdc7515fd18464ab2e5d9035f 100644 --- a/app/models/communication/website/with_security.rb +++ b/app/models/communication/website/with_security.rb @@ -5,7 +5,10 @@ module Communication::Website::WithSecurity list = external_domains_default list.concat external_domains_plausible list.concat external_domains_from_blocks_video - list.concat external_domains_from_blocks_embed + list.concat external_domains_from_blocks_embed(blocks) + list.concat external_domains_from_blocks_embed(blocks_from_education) + list.concat external_domains_from_blocks_embed(blocks_from_research) + list.concat external_domains_from_blocks_embed(blocks_from_university) list.uniq.compact end @@ -34,14 +37,14 @@ module Communication::Website::WithSecurity list end - def external_domains_from_blocks_embed + def external_domains_from_blocks_embed(blocks) list = [] - blocks.where(template_kind: :embed).each do |block| + blocks.where(template_kind: :embed).published.each do |block| code = block.template.code # https://stackoverflow.com/questions/25095176/extracting-all-urls-from-a-page-using-ruby code.scan(/[[:lower:]]+:\/\/[^\s"]+/).each do |url| url = CGI.unescapeHTML(url) - url = ActionController::Base.helpers.strip_tags(url) + url = ActionController::Base.helpers.strip_tags(url) url = URI::Parser.new.escape(url) host = URI.parse(url).host list << host diff --git a/app/services/video/provider.rb b/app/services/video/provider.rb index 5b6f3fd68892b3651781a45f47d6e700b448b53a..ea50081e1f9128e3e19b9ec80c4988f90199ea2e 100644 --- a/app/services/video/provider.rb +++ b/app/services/video/provider.rb @@ -2,7 +2,8 @@ class Video::Provider PROVIDERS = [ Vimeo, Youtube, - Dailymotion + Dailymotion, + Peertube ] def self.find(video_url) diff --git a/app/services/video/provider/peertube.rb b/app/services/video/provider/peertube.rb new file mode 100644 index 0000000000000000000000000000000000000000..6bcdc3966e467fa6927398d4b121a830230feb77 --- /dev/null +++ b/app/services/video/provider/peertube.rb @@ -0,0 +1,17 @@ +class Video::Provider::Peertube < Video::Provider::Default + DOMAINS = ['peertube.fr', 'peertude.my.noesya.coop'] + + # "https://peertube.fr/w/1i848Qvi7Q3ytW2uPY8AxG" + def identifier + video_url.split('/w/').last + end + + def host + video_url.split('/w/').first + end + + # https://docs.joinpeertube.org/support/doc/api/embeds#quick-start + def iframe_url + "#{host}/videos/embed/#{identifier}" + end +end