Files
grecia/app/components/shared/embedded_video_component.rb
Javi Martín ee64efe659 Use the Do Not Track parameter in vimeo videos
With this parameter, Vimeo no longer uses cookies that identifies users
browsing our site.

They do still store some cookies, though; quoting from Vimeo player
parameters overview:

> When DNT is enabled, Vimeo deploys one essential cookie via the
> embeddable player:
> The __cf_bm cookie, which is part of Cloudflare's Bot Management
> service and helps mitigate risk associated with spam and bot traffic.

Not sure whether this counts as essential cookies in our case; they're
essential for Vimeo, but for us, they're third-party cookies, after all.

[1] https://help.vimeo.com/hc/en-us/articles/12426260232977-Player-parameters-overview
2024-06-07 15:28:42 +02:00

60 lines
1.1 KiB
Ruby

class Shared::EmbeddedVideoComponent < ApplicationComponent
attr_reader :record
def initialize(record)
@record = record
end
def render?
record.video_url.present?
end
def embedded_video_code
if match && match[2]
"<iframe #{iframe_attributes}></iframe>"
end
end
private
def link
record.video_url
end
def title
t("proposals.show.embed_video_title", proposal: record.title)
end
def server
if link =~ /vimeo.*/
"Vimeo"
elsif link =~ /youtu*.*/
"YouTube"
end
end
def regex
if server == "Vimeo"
record.class::VIMEO_REGEX
elsif server == "YouTube"
record.class::YOUTUBE_REGEX
end
end
def src
if server == "Vimeo"
"https://player.vimeo.com/video/#{match[2]}?dnt=1"
elsif server == "YouTube"
"https://www.youtube-nocookie.com/embed/#{match[2]}"
end
end
def match
@match ||= link.match(regex) if regex
end
def iframe_attributes
tag.attributes(src: src, style: "border:0;", allowfullscreen: true, title: title)
end
end