fix dependency
All checks were successful
/ Run tests (push) Successful in 1m43s
/ Run system tests (push) Successful in 2m17s
/ Build, push and deploy image (push) Successful in 1m54s

This commit is contained in:
david 2024-07-26 03:26:57 +02:00
parent 109dcd205c
commit aad67af0d1

View file

@ -1,3 +1,5 @@
require 'net/http'
class Link < ApplicationRecord
belongs_to :link_category
has_rich_text :description_html
@ -14,11 +16,11 @@ class Link < ApplicationRecord
private
USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0"
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0'
def check_url(input = url, add_error = true)
response = begin
Net::HTTP.get_response(URI.parse(input), "User-Agent": USER_AGENT)
Net::HTTP.get_response(URI.parse(input), 'User-Agent': USER_AGENT)
rescue Socket::ResolutionError
errors.add(:url, :invalid) if add_error
return false
@ -42,10 +44,10 @@ class Link < ApplicationRecord
end
def ensure_absolute_url
self.url = "https://#{self.url}" unless self.url.match?(%r{https{0,1}://.*})
self.url = "https://#{url}" unless url.match?(%r{https{0,1}://.*})
end
def valid_url
errors.add(:url, :invalid) unless url.match /\A#{URI::regexp(['http', 'https'])}\z/
errors.add(:url, :invalid) unless url.match(/\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/)
end
end