Refactor sources
This commit is contained in:
@@ -4,13 +4,8 @@ class UploadService
|
||||
upload = Upload.new
|
||||
|
||||
if Utils.is_downloadable?(url) && file.nil?
|
||||
download = Downloads::File.new(url)
|
||||
normalized_url = download.rewrite_url()
|
||||
post = if normalized_url.nil?
|
||||
Post.where("SourcePattern(lower(posts.source)) = ?", url).first
|
||||
else
|
||||
Post.where("SourcePattern(lower(posts.source)) IN (?)", [url, normalized_url]).first
|
||||
end
|
||||
strategy = Sources::Strategies.find(url, ref)
|
||||
post = Post.where("SourcePattern(lower(posts.source)) IN (?)", [url, strategy.canonical_url]).first
|
||||
|
||||
if post.nil?
|
||||
# this gets called from UploadsController#new so we need
|
||||
@@ -19,13 +14,15 @@ class UploadService
|
||||
end
|
||||
|
||||
begin
|
||||
source = Sources::Site.new(url, :referer_url => ref)
|
||||
download = Downloads::File.new(url, ref)
|
||||
remote_size = download.size
|
||||
rescue Exception
|
||||
end
|
||||
|
||||
return [upload, post, source, normalized_url, remote_size]
|
||||
elsif file
|
||||
return [upload, post, strategy, remote_size]
|
||||
end
|
||||
|
||||
if file
|
||||
# this gets called via XHR so we can process sync
|
||||
Preprocessor.new(file: file).delayed_start(CurrentUser.id)
|
||||
end
|
||||
@@ -35,9 +32,7 @@ class UploadService
|
||||
|
||||
def self.batch(url, ref = nil)
|
||||
if url
|
||||
source = Sources::Site.new(url, :referer_url => ref)
|
||||
source.get
|
||||
return source
|
||||
return Sources::Strategies.find(url, ref)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user