Skip to content

Commit

Permalink
Move submission_url into the simple definition
Browse files Browse the repository at this point in the history
Allows you to view files of scrapers that were removed
  • Loading branch information
Earlopain committed Oct 11, 2023
1 parent 84ee8dc commit c505ed3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 0 additions & 12 deletions app/logical/sites/scraper_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,11 @@

module Sites
class ScraperDefinition < SimpleDefinition
attr_reader :submission_template

def initialize(definition_data)
super
@submission_template = Addressable::Template.new(definition_data["submission_template"])
@image_domains = definition_data["image_domains"] || []
@download_headers = definition_data["download_headers"] || {}
@scraper = "Scraper::#{site_type.camelize}".constantize
end

def submission_url(submission)
submission_template.expand(
site_artist_identifier: submission.artist_url.url_identifier,
site_submission_identifier: submission.identifier_on_site,
).to_s
end

def missing_config_keys
@scraper.required_config_keys.select { |key| Config.send(key).blank? }
end
Expand Down
12 changes: 10 additions & 2 deletions app/logical/sites/simple_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ def initialize(definition_data)
@homepage = definition_data["homepage"]
@gallery_templates = definition_data["gallery_templates"].map { |t| Addressable::Template.new("{prefix}#{t}{/remaining}{?remaining}{#remaining}") }
@username_identifier_regex = Regexp.new("^#{definition_data['username_identifier_regex']}$")
@image_domains = []
@download_headers = {}
@submission_template = Addressable::Template.new(definition_data["submission_template"]) if definition_data["submission_template"]
@image_domains = definition_data["image_domains"] || []
@download_headers = definition_data["download_headers"] || {}
end

def match_for_gallery(uri)
Expand All @@ -35,6 +36,13 @@ def gallery_url(identifier)
"https://#{gallery_templates.first.expand(site_artist_identifier: identifier)}"
end

def submission_url(submission)
@submission_template.expand(
site_artist_identifier: submission.artist_url.url_identifier,
site_submission_identifier: submission.identifier_on_site,
).to_s
end

def missing_config_keys
[]
end
Expand Down

0 comments on commit c505ed3

Please sign in to comment.