@@ -22,6 +22,11 @@ module Downloads
|
|||||||
@data[:get_thumbnail] = options[:get_thumbnail]
|
@data[:get_thumbnail] = options[:get_thumbnail]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rewrite_url
|
||||||
|
url, _, _ = before_download(@source, @data)
|
||||||
|
return url
|
||||||
|
end
|
||||||
|
|
||||||
def size
|
def size
|
||||||
url, headers, _ = before_download(@source, @data)
|
url, headers, _ = before_download(@source, @data)
|
||||||
options = { timeout: 3, headers: headers }.deep_merge(Danbooru.config.httparty_options)
|
options = { timeout: 3, headers: headers }.deep_merge(Danbooru.config.httparty_options)
|
||||||
|
|||||||
@@ -103,9 +103,9 @@ class StorageManager::Match < StorageManager
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_path(post, type, **options)
|
def file_path(post, file_ext, type, **options)
|
||||||
find(id: post.id, type: type) do |manager|
|
find(id: post.id, type: type) do |manager|
|
||||||
manager.file_path(post, type, **options)
|
manager.file_path(post, file_ext, type, **options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,9 +15,15 @@ class UploadService
|
|||||||
params[:md5_confirmation]
|
params[:md5_confirmation]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def normalized_source
|
||||||
|
@normalized_source ||= begin
|
||||||
|
Downloads::File.new(params[:source]).rewrite_url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def in_progress?
|
def in_progress?
|
||||||
if Utils.is_downloadable?(source)
|
if Utils.is_downloadable?(source)
|
||||||
Upload.where(status: "preprocessing", source: source).exists?
|
Upload.where(status: "preprocessing", source: normalized_source).exists?
|
||||||
elsif md5.present?
|
elsif md5.present?
|
||||||
Upload.where(status: "preprocessing", md5: md5).exists?
|
Upload.where(status: "preprocessing", md5: md5).exists?
|
||||||
else
|
else
|
||||||
@@ -27,7 +33,7 @@ class UploadService
|
|||||||
|
|
||||||
def predecessor
|
def predecessor
|
||||||
if Utils.is_downloadable?(source)
|
if Utils.is_downloadable?(source)
|
||||||
Upload.where(status: ["preprocessed", "preprocessing"], source: source).first
|
Upload.where(status: ["preprocessed", "preprocessing"], source: normalized_source).first
|
||||||
elsif md5.present?
|
elsif md5.present?
|
||||||
Upload.where(status: ["preprocessed", "preprocessing"], md5: md5).first
|
Upload.where(status: ["preprocessed", "preprocessing"], md5: md5).first
|
||||||
end
|
end
|
||||||
@@ -49,17 +55,17 @@ class UploadService
|
|||||||
def start!
|
def start!
|
||||||
if Utils.is_downloadable?(source)
|
if Utils.is_downloadable?(source)
|
||||||
CurrentUser.as_system do
|
CurrentUser.as_system do
|
||||||
if Post.tag_match("source:#{source}").where.not(id: original_post_id).exists?
|
if Post.tag_match("source:#{normalized_source}").where.not(id: original_post_id).exists?
|
||||||
raise ActiveRecord::RecordNotUnique.new("A post with source #{source} already exists")
|
raise ActiveRecord::RecordNotUnique.new("A post with source #{normalized_source} already exists")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Upload.where(source: source, status: "completed").exists?
|
if Upload.where(source: normalized_source, status: "completed").exists?
|
||||||
raise ActiveRecord::RecordNotUnique.new("A completed upload with source #{source} already exists")
|
raise ActiveRecord::RecordNotUnique.new("A completed upload with source #{normalized_source} already exists")
|
||||||
end
|
end
|
||||||
|
|
||||||
if Upload.where(source: source).where("status like ?", "error%").exists?
|
if Upload.where(source: normalized_source).where("status like ?", "error%").exists?
|
||||||
raise ActiveRecord::RecordNotUnique.new("An errored upload with source #{source} already exists")
|
raise ActiveRecord::RecordNotUnique.new("An errored upload with source #{normalized_source} already exists")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user