Fix #3982: Uploads: URI::InvalidURIError - URI must be ascii only.
This commit is contained in:
@@ -48,7 +48,7 @@ class UploadService
|
||||
|
||||
@upload.update(status: "processing")
|
||||
|
||||
if @upload.file.nil? && Utils.is_downloadable?(source)
|
||||
if @upload.file.nil? && @upload.source_url.present?
|
||||
@upload.file = Utils.download_for_upload(@upload)
|
||||
end
|
||||
|
||||
@@ -71,10 +71,6 @@ class UploadService
|
||||
return @post.warnings.full_messages
|
||||
end
|
||||
|
||||
def source
|
||||
params[:source]
|
||||
end
|
||||
|
||||
def include_artist_commentary?
|
||||
params[:include_artist_commentary].to_s.truthy?
|
||||
end
|
||||
|
||||
@@ -93,7 +93,7 @@ class UploadService
|
||||
|
||||
if params[:file].present?
|
||||
file = params[:file]
|
||||
elsif Utils.is_downloadable?(source)
|
||||
elsif upload.source_url.present?
|
||||
file = Utils.download_for_upload(upload)
|
||||
end
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ class UploadService
|
||||
attempts = 0
|
||||
|
||||
begin
|
||||
download = Downloads::File.new(upload.source, upload.referer_url)
|
||||
download = Downloads::File.new(upload.source_url, upload.referer_url)
|
||||
file, strategy = download.download!
|
||||
|
||||
if !DanbooruImageResizer.validate_shell(file)
|
||||
|
||||
@@ -135,6 +135,24 @@ class Upload < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module SourceMethods
|
||||
def source=(source)
|
||||
source = source.unicode_normalize(:nfc)
|
||||
|
||||
# percent encode unicode characters in urls
|
||||
if source =~ %r!\Ahttps?://!i
|
||||
source = Addressable::URI.normalized_encode(source) rescue source
|
||||
end
|
||||
|
||||
super(source)
|
||||
end
|
||||
|
||||
def source_url
|
||||
return nil unless source =~ %r!\Ahttps?://!i
|
||||
Addressable::URI.heuristic_parse(source) rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
module UploaderMethods
|
||||
def uploader_name
|
||||
User.id_to_name(uploader_id)
|
||||
@@ -233,6 +251,7 @@ class Upload < ApplicationRecord
|
||||
include VideoMethods
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
include SourceMethods
|
||||
|
||||
def uploader_is_not_limited
|
||||
if !uploader.can_upload?
|
||||
|
||||
Reference in New Issue
Block a user