Merge pull request #4547 from nonamethanks/fix_4545
Uploads: Check if strategy is enabled before use
This commit is contained in:
@@ -77,6 +77,10 @@ module Sources
|
|||||||
|
|
||||||
FAVME = %r{\Ahttps?://(?:www\.)?fav\.me/d(?<base36_deviation_id>[a-z0-9]+)\z}i
|
FAVME = %r{\Ahttps?://(?:www\.)?fav\.me/d(?<base36_deviation_id>[a-z0-9]+)\z}i
|
||||||
|
|
||||||
|
def self.enabled?
|
||||||
|
Danbooru.config.deviantart_client_id.present? && Danbooru.config.deviantart_client_secret.present?
|
||||||
|
end
|
||||||
|
|
||||||
def domains
|
def domains
|
||||||
["deviantart.net", "deviantart.com", "fav.me"]
|
["deviantart.net", "deviantart.com", "fav.me"]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ module Sources
|
|||||||
|
|
||||||
PROFILE_PAGE = %r{\Ahttps?://seiga\.nicovideo\.jp/user/illust/(?<artist_id>\d+)}i
|
PROFILE_PAGE = %r{\Ahttps?://seiga\.nicovideo\.jp/user/illust/(?<artist_id>\d+)}i
|
||||||
|
|
||||||
|
def self.enabled?
|
||||||
|
Danbooru.config.nico_seiga_login.present? && Danbooru.config.nico_seiga_password.present?
|
||||||
|
end
|
||||||
|
|
||||||
def domains
|
def domains
|
||||||
["nicoseiga.jp", "nicovideo.jp"]
|
["nicoseiga.jp", "nicovideo.jp"]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ module Sources
|
|||||||
DIR = %r{(?:\d+/)?(?:__rs_\w+/)?nijie_picture(?:/diff/main)?}
|
DIR = %r{(?:\d+/)?(?:__rs_\w+/)?nijie_picture(?:/diff/main)?}
|
||||||
IMAGE_URL = %r{#{IMAGE_BASE_URL}/#{DIR}/#{Regexp.union(FILENAME1, FILENAME2, FILENAME3)}\.\w+\z}i
|
IMAGE_URL = %r{#{IMAGE_BASE_URL}/#{DIR}/#{Regexp.union(FILENAME1, FILENAME2, FILENAME3)}\.\w+\z}i
|
||||||
|
|
||||||
|
def self.enabled?
|
||||||
|
Danbooru.config.nijie_login.present? && Danbooru.config.nijie_password.present?
|
||||||
|
end
|
||||||
|
|
||||||
def domains
|
def domains
|
||||||
["nijie.info", "nijie.net"]
|
["nijie.info", "nijie.net"]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ module Sources::Strategies
|
|||||||
STATUS1 = %r{\A#{HOST}/web/statuses/(?<status_id>\d+)}
|
STATUS1 = %r{\A#{HOST}/web/statuses/(?<status_id>\d+)}
|
||||||
STATUS2 = %r{\A#{NAMED_PROFILE}/(?<status_id>\d+)}
|
STATUS2 = %r{\A#{NAMED_PROFILE}/(?<status_id>\d+)}
|
||||||
|
|
||||||
|
def self.enabled?
|
||||||
|
Danbooru.config.pawoo_client_id.present? && Danbooru.config.pawoo_client_secret.present?
|
||||||
|
end
|
||||||
|
|
||||||
def domains
|
def domains
|
||||||
["pawoo.net"]
|
["pawoo.net"]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,6 +65,10 @@ module Sources
|
|||||||
STACC_PAGE = %r{\A#{WEB}/stacc/#{MONIKER}/?\z}i
|
STACC_PAGE = %r{\A#{WEB}/stacc/#{MONIKER}/?\z}i
|
||||||
NOVEL_PAGE = %r{(?:\Ahttps?://www\.pixiv\.net/novel/show\.php\?id=(\d+))}
|
NOVEL_PAGE = %r{(?:\Ahttps?://www\.pixiv\.net/novel/show\.php\?id=(\d+))}
|
||||||
|
|
||||||
|
def self.enabled?
|
||||||
|
Danbooru.config.pixiv_login.present? && Danbooru.config.pixiv_password.present?
|
||||||
|
end
|
||||||
|
|
||||||
def self.to_dtext(text)
|
def self.to_dtext(text)
|
||||||
if text.nil?
|
if text.nil?
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ class UploadService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start!
|
def start!
|
||||||
|
raise NotImplementedError, "No login credentials configured for #{strategy.site_name}." unless strategy.class.enabled?
|
||||||
|
|
||||||
if Utils.is_downloadable?(source)
|
if Utils.is_downloadable?(source)
|
||||||
if Post.system_tag_match("source:#{canonical_source}").where.not(id: original_post_id).exists?
|
if Post.system_tag_match("source:#{canonical_source}").where.not(id: original_post_id).exists?
|
||||||
raise ActiveRecord::RecordNotUnique, "A post with source #{canonical_source} already exists"
|
raise ActiveRecord::RecordNotUnique, "A post with source #{canonical_source} already exists"
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ class UploadService
|
|||||||
raise "No file or source URL provided" if upload.source_url.blank?
|
raise "No file or source URL provided" if upload.source_url.blank?
|
||||||
|
|
||||||
strategy = Sources::Strategies.find(upload.source_url, upload.referer_url)
|
strategy = Sources::Strategies.find(upload.source_url, upload.referer_url)
|
||||||
|
raise NotImplementedError, "No login credentials configured for #{strategy.site_name}." unless strategy.class.enabled?
|
||||||
|
|
||||||
file = strategy.download_file!
|
file = strategy.download_file!
|
||||||
|
|
||||||
if strategy.data[:ugoira_frame_data].present?
|
if strategy.data[:ugoira_frame_data].present?
|
||||||
|
|||||||
Reference in New Issue
Block a user