Add alt_source field on uploads to deal with twitter galleries

This commit is contained in:
r888888888
2018-08-04 13:59:36 -07:00
parent 7c524f867b
commit 334d8b7c6f
5 changed files with 263 additions and 153 deletions

View File

@@ -15,7 +15,13 @@ class UploadService
params[:md5_confirmation]
end
def referer
params[:referer_url]
end
def normalized_source
# problem: for batch twitter, the source is saved as
# the twimg url,
@normalized_source ||= begin
Downloads::File.new(params[:source]).rewrite_url
end
@@ -23,7 +29,7 @@ class UploadService
def in_progress?
if Utils.is_downloadable?(source)
Upload.where(status: "preprocessing", source: normalized_source).exists?
Upload.where(status: "preprocessing", source: normalized_source).or(Upload.where(status: "preprocessing", alt_source: normalized_source)).exists?
elsif md5.present?
Upload.where(status: "preprocessing", md5: md5).exists?
else
@@ -33,7 +39,7 @@ class UploadService
def predecessor
if Utils.is_downloadable?(source)
Upload.where(status: ["preprocessed", "preprocessing"], source: normalized_source).first
Upload.where(status: ["preprocessed", "preprocessing"]).where(source: normalized_source).or(Upload.where(status: ["preprocessed", "preprocessing"], alt_source: normalized_source)).first
elsif md5.present?
Upload.where(status: ["preprocessed", "preprocessing"], md5: md5).first
end
@@ -76,7 +82,10 @@ class UploadService
begin
upload.update(status: "preprocessing")
if source.present?
if Utils.is_downloadable?(source)
# preserve the original source (for twitter, the twimg:orig
# source, while the status url is stored in upload.source)
upload.alt_source = normalized_source
file = Utils.download_for_upload(source, upload)
elsif params[:file].present?
file = params[:file]
@@ -101,7 +110,9 @@ class UploadService
# regardless of who initialized the upload, credit should goto whoever submitted the form
pred.initialize_attributes
pred.attributes = self.params
# we went through a lot of trouble normalizing the source,
# so don't overwrite it with whatever the user provided
pred.attributes = self.params.except(:source)
# if a file was uploaded after the preprocessing occurred,
# then process the file and overwrite whatever the preprocessor

View File

@@ -47,6 +47,15 @@
</span>
<br>
<% if upload.alt_source.present? %>
<span class="info">
<strong>Alternate Source</strong>
<%= link_to_if (upload.alt_source =~ %r!\Ahttps?://!i), (upload.alt_source.presence.try(:truncate, 50) || content_tag(:em, "none")), upload.source %>
<%= link_to "»", uploads_path(search: params[:search].merge(source_matches: upload.alt_source)) %>
</span>
<br>
<% end %>
<span class="info">
<strong>Tags</strong>
<%= TagSetPresenter.new(upload.tag_string.split).inline_tag_list_html(self) %>