Refactor sources

This commit is contained in:
Albert Yi
2018-08-06 17:39:25 -07:00
parent 54363ffecf
commit 762dc3da24
71 changed files with 2340 additions and 2430 deletions

View File

@@ -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