Fix misc rubocop warnings.

This commit is contained in:
evazion
2020-06-16 21:36:15 -05:00
parent dc460aab53
commit b551e3634f
25 changed files with 75 additions and 95 deletions

View File

@@ -13,7 +13,7 @@ class UploadService
rescue Exception
end
return [upload, remote_size]
[upload, remote_size]
end
if file
@@ -21,7 +21,7 @@ class UploadService
Preprocessor.new(file: file).delayed_start(CurrentUser.id)
end
return [upload]
[upload]
end
end
end

View File

@@ -46,11 +46,9 @@ class UploadService
def predecessor
if md5.present?
return Upload.where(status: ["preprocessed", "preprocessing"], md5: md5).first
end
if Utils.is_downloadable?(source)
return Upload.where(status: ["preprocessed", "preprocessing"], source: source).first
Upload.where(status: ["preprocessed", "preprocessing"], md5: md5).first
elsif Utils.is_downloadable?(source)
Upload.where(status: ["preprocessed", "preprocessing"], source: source).first
end
end
@@ -63,21 +61,20 @@ class UploadService
start!
end
rescue ActiveRecord::RecordNotUnique
return
end
def start!
if Utils.is_downloadable?(source)
if Post.system_tag_match("source:#{canonical_source}").where.not(id: original_post_id).exists?
raise ActiveRecord::RecordNotUnique.new("A post with source #{canonical_source} already exists")
raise ActiveRecord::RecordNotUnique, "A post with source #{canonical_source} already exists"
end
if Upload.where(source: source, status: "completed").exists?
raise ActiveRecord::RecordNotUnique.new("A completed upload with source #{source} already exists")
raise ActiveRecord::RecordNotUnique, "A completed upload with source #{source} already exists"
end
if Upload.where(source: source).where("status like ?", "error%").exists?
raise ActiveRecord::RecordNotUnique.new("An errored upload with source #{source} already exists")
raise ActiveRecord::RecordNotUnique, "An errored upload with source #{source} already exists"
end
end
@@ -95,21 +92,21 @@ class UploadService
upload.tag_string = params[:tag_string]
upload.status = "preprocessed"
upload.save!
rescue Exception => x
upload.update(file_ext: nil, status: "error: #{x.class} - #{x.message}", backtrace: x.backtrace.join("\n"))
rescue Exception => e
upload.update(file_ext: nil, status: "error: #{e.class} - #{e.message}", backtrace: e.backtrace.join("\n"))
end
return upload
upload
end
def finish!(upload = nil)
pred = upload || self.predecessor
pred = upload || predecessor
# regardless of who initialized the upload, credit should
# goto whoever submitted the form
pred.initialize_attributes
pred.attributes = self.params
pred.attributes = params
# if a file was uploaded after the preprocessing occurred,
# then process the file and overwrite whatever the preprocessor
@@ -118,7 +115,7 @@ class UploadService
pred.status = "completed"
pred.save
return pred
pred
end
end
end

View File

@@ -62,7 +62,7 @@ class UploadService
end
def source_strategy(upload)
return Sources::Strategies.find(upload.source, upload.referer_url)
Sources::Strategies.find(upload.source, upload.referer_url)
end
def find_replacement_url(repl, upload)
@@ -78,7 +78,7 @@ class UploadService
return source_strategy(upload).canonical_url
end
return upload.source
upload.source
end
def process!

View File

@@ -83,7 +83,7 @@ class UploadService
}
end
return file
file
end
end
end