uploads: remove useless code.
This commit is contained in:
@@ -2,10 +2,9 @@ class UploadService
|
|||||||
class Preprocessor
|
class Preprocessor
|
||||||
extend Memoist
|
extend Memoist
|
||||||
|
|
||||||
attr_reader :params, :original_post_id
|
attr_reader :params
|
||||||
|
|
||||||
def initialize(params)
|
def initialize(params)
|
||||||
@original_post_id = params.delete(:original_post_id) || -1
|
|
||||||
@params = params
|
@params = params
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -21,17 +20,6 @@ class UploadService
|
|||||||
params[:referer_url]
|
params[:referer_url]
|
||||||
end
|
end
|
||||||
|
|
||||||
def strategy
|
|
||||||
Sources::Strategies.find(source, referer_url)
|
|
||||||
end
|
|
||||||
memoize :strategy
|
|
||||||
|
|
||||||
# When searching posts we have to use the canonical source
|
|
||||||
def canonical_source
|
|
||||||
strategy.canonical_url
|
|
||||||
end
|
|
||||||
memoize :canonical_source
|
|
||||||
|
|
||||||
def in_progress?
|
def in_progress?
|
||||||
if md5.present?
|
if md5.present?
|
||||||
Upload.exists?(status: "preprocessing", md5: md5)
|
Upload.exists?(status: "preprocessing", md5: md5)
|
||||||
@@ -62,8 +50,6 @@ class UploadService
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start!
|
def start!
|
||||||
raise NotImplementedError, "No login credentials configured for #{strategy.site_name}." unless strategy.class.enabled?
|
|
||||||
|
|
||||||
params[:rating] ||= "q"
|
params[:rating] ||= "q"
|
||||||
params[:tag_string] ||= "tagme"
|
params[:tag_string] ||= "tagme"
|
||||||
upload = Upload.create!(params)
|
upload = Upload.create!(params)
|
||||||
@@ -72,7 +58,7 @@ class UploadService
|
|||||||
upload.update(status: "preprocessing")
|
upload.update(status: "preprocessing")
|
||||||
|
|
||||||
file = Utils.get_file_for_upload(upload.source_url, upload.referer_url, params[:file]&.tempfile)
|
file = Utils.get_file_for_upload(upload.source_url, upload.referer_url, params[:file]&.tempfile)
|
||||||
Utils.process_file(upload, file, original_post_id: original_post_id)
|
Utils.process_file(upload, file)
|
||||||
|
|
||||||
upload.rating = params[:rating]
|
upload.rating = params[:rating]
|
||||||
upload.tag_string = params[:tag_string]
|
upload.tag_string = params[:tag_string]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class UploadService
|
|||||||
source =~ %r{\Ahttps?://}
|
source =~ %r{\Ahttps?://}
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_file(upload, file, original_post_id: nil)
|
def process_file(upload, file)
|
||||||
media_file = MediaFile.open(file)
|
media_file = MediaFile.open(file)
|
||||||
|
|
||||||
upload.file = media_file
|
upload.file = media_file
|
||||||
|
|||||||
@@ -28,12 +28,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
@upload = FactoryBot.build(:jpg_upload)
|
@upload = FactoryBot.build(:jpg_upload)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with an original_post_id" do
|
|
||||||
should "run" do
|
|
||||||
UploadService::Utils.process_file(@upload, @upload.file.tempfile, original_post_id: 12345)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
should "run" do
|
should "run" do
|
||||||
UploadService::Utils.process_file(@upload, @upload.file.tempfile)
|
UploadService::Utils.process_file(@upload, @upload.file.tempfile)
|
||||||
assert_equal("jpg", @upload.file_ext)
|
assert_equal("jpg", @upload.file_ext)
|
||||||
@@ -723,7 +717,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_equal(true, upload.valid?)
|
assert_equal(true, upload.valid?)
|
||||||
assert_equal("s", upload.rating)
|
assert_equal("s", upload.rating)
|
||||||
assert_equal("rating:safe blah ", upload.tag_string)
|
assert_equal("rating:safe blah", upload.tag_string)
|
||||||
|
|
||||||
assert_equal("s", upload.post.rating)
|
assert_equal("s", upload.post.rating)
|
||||||
assert_equal("blah", upload.post.tag_string)
|
assert_equal("blah", upload.post.tag_string)
|
||||||
|
|||||||
Reference in New Issue
Block a user