sources: rename Sources::Strategies to Source::Extractor.
Rename Sources::Strategies to Source::Extractor. A Source::Extractor represents a thing that extracts information from a given URL.
This commit is contained in:
@@ -156,7 +156,7 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
if source.present?
|
||||
artist = Sources::Strategies.find(source).new_artist
|
||||
artist = Source::Extractor.find(source).new_artist
|
||||
artist.attributes = params
|
||||
else
|
||||
artist = Artist.new(params)
|
||||
@@ -252,7 +252,7 @@ class Artist < ApplicationRecord
|
||||
elsif query.include?("*")
|
||||
where(id: ArtistURL.where_like(:url, query).select(:artist_id))
|
||||
elsif query =~ %r{\Ahttps?://}i
|
||||
url = Sources::Strategies.find(query).profile_url || query
|
||||
url = Source::Extractor.find(query).profile_url || query
|
||||
ArtistFinder.find_artists(url)
|
||||
else
|
||||
where(id: ArtistURL.where_like(:url, "*#{query}*").select(:artist_id))
|
||||
|
||||
@@ -53,7 +53,7 @@ class ArtistURL < ApplicationRecord
|
||||
elsif url.include?("*")
|
||||
where_ilike(attr, url)
|
||||
else
|
||||
profile_url = Sources::Strategies.find(url).profile_url || url
|
||||
profile_url = Source::Extractor.find(url).profile_url || url
|
||||
where(attr => normalize_normalized_url(profile_url))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -87,7 +87,7 @@ class Post < ApplicationRecord
|
||||
)
|
||||
|
||||
if add_artist_tag
|
||||
tag_string = "#{tag_string} #{upload_media_asset.source_strategy&.artists.to_a.map(&:tag).map(&:name).join(" ")}".strip
|
||||
tag_string = "#{tag_string} #{upload_media_asset.source_extractor&.artists.to_a.map(&:tag).map(&:name).join(" ")}".strip
|
||||
tag_string += " " if tag_string.present?
|
||||
end
|
||||
|
||||
@@ -1157,7 +1157,7 @@ class Post < ApplicationRecord
|
||||
self.pixiv_id = nil
|
||||
return unless web_source?
|
||||
|
||||
site = Sources::Strategies::Pixiv.new(source)
|
||||
site = Source::Extractor::Pixiv.new(source)
|
||||
if site.match?
|
||||
self.pixiv_id = site.illust_id
|
||||
end
|
||||
@@ -1265,7 +1265,7 @@ class Post < ApplicationRecord
|
||||
return if !web_source?
|
||||
return if has_tag?("artist_request") || has_tag?("official_art")
|
||||
return if tags.any?(&:artist?)
|
||||
return if Sources::Strategies.find(source).is_a?(Sources::Strategies::Null)
|
||||
return if Source::Extractor.find(source).is_a?(Source::Extractor::Null)
|
||||
|
||||
new_artist_path = Routes.new_artist_path(artist: { source: source })
|
||||
warnings.add(:base, "Artist tag is required. \"Create new artist tag\":[#{new_artist_path}]. Ask on the forum if you need naming help")
|
||||
|
||||
@@ -117,8 +117,8 @@ class Upload < ApplicationRecord
|
||||
UploadMediaAsset.new(file: file.tempfile, source_url: "file://#{file.original_filename}")
|
||||
end
|
||||
elsif source.present?
|
||||
page_url = source_strategy.page_url
|
||||
image_urls = source_strategy.image_urls
|
||||
page_url = source_extractor.page_url
|
||||
image_urls = source_extractor.image_urls
|
||||
|
||||
if image_urls.empty?
|
||||
raise Error, "#{source} doesn't contain any images"
|
||||
@@ -136,14 +136,14 @@ class Upload < ApplicationRecord
|
||||
update!(status: "error", error: e.message)
|
||||
end
|
||||
|
||||
def source_strategy
|
||||
def source_extractor
|
||||
return nil if source.blank?
|
||||
Sources::Strategies.find(source, referer_url)
|
||||
Source::Extractor.find(source, referer_url)
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
[:uploader, :upload_media_assets, :media_assets, :posts]
|
||||
end
|
||||
|
||||
memoize :source_strategy
|
||||
memoize :source_extractor
|
||||
end
|
||||
|
||||
@@ -79,9 +79,9 @@ class UploadMediaAsset < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def source_strategy
|
||||
def source_extractor
|
||||
return nil if source_url.blank?
|
||||
Sources::Strategies.find(source_url, page_url)
|
||||
Source::Extractor.find(source_url, page_url)
|
||||
end
|
||||
|
||||
def async_process_upload!
|
||||
@@ -98,7 +98,7 @@ class UploadMediaAsset < ApplicationRecord
|
||||
if file.present?
|
||||
media_file = MediaFile.open(file)
|
||||
else
|
||||
media_file = source_strategy.download_file!(source_url)
|
||||
media_file = source_extractor.download_file!(source_url)
|
||||
end
|
||||
|
||||
MediaAsset.upload!(media_file) do |media_asset|
|
||||
@@ -120,5 +120,5 @@ class UploadMediaAsset < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
memoize :source_strategy
|
||||
memoize :source_extractor
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user