add support for upload preprocessing
This commit is contained in:
@@ -3,31 +3,14 @@ class UploadsController < ApplicationController
|
||||
respond_to :html, :xml, :json, :js
|
||||
|
||||
def new
|
||||
@upload = Upload.new
|
||||
@upload_notice_wiki = WikiPage.titled(Danbooru.config.upload_notice_wiki_page).first
|
||||
if params[:url]
|
||||
download = Downloads::File.new(params[:url])
|
||||
@normalized_url, _, _ = download.before_download(params[:url], {})
|
||||
@post = find_post_by_url(@normalized_url)
|
||||
|
||||
begin
|
||||
@source = Sources::Site.new(params[:url], :referer_url => params[:ref])
|
||||
@remote_size = download.size
|
||||
rescue Exception
|
||||
end
|
||||
end
|
||||
@upload, @post, @source, @normalized_url, @remote_size = UploadService::ControllerHelper.prepare(params[:url], params[:ref])
|
||||
respond_with(@upload)
|
||||
end
|
||||
|
||||
def batch
|
||||
@url = params.dig(:batch, :url) || params[:url]
|
||||
@source = nil
|
||||
|
||||
if @url
|
||||
@source = Sources::Site.new(@url, :referer_url => params[:ref])
|
||||
@source.get
|
||||
end
|
||||
|
||||
@source = UploadService::ControllerHelper.batch(@url, params[:ref])
|
||||
respond_with(@source)
|
||||
end
|
||||
|
||||
@@ -57,14 +40,11 @@ class UploadsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@upload = Upload.create(upload_params)
|
||||
@service = UploadService.new(upload_params)
|
||||
@upload = @service.start!
|
||||
|
||||
if @upload.errors.empty?
|
||||
post = @upload.process!
|
||||
|
||||
if post.present? && post.valid? && post.warnings.any?
|
||||
flash[:notice] = post.warnings.full_messages.join(".\n \n")
|
||||
end
|
||||
if @service.warnings.any?
|
||||
flash[:notice] = @service.warnings.join(".\n \n")
|
||||
end
|
||||
|
||||
save_recent_tags
|
||||
@@ -73,14 +53,6 @@ class UploadsController < ApplicationController
|
||||
|
||||
private
|
||||
|
||||
def find_post_by_url(normalized_url)
|
||||
if normalized_url.nil?
|
||||
Post.where("SourcePattern(lower(posts.source)) = ?", params[:url]).first
|
||||
else
|
||||
Post.where("SourcePattern(lower(posts.source)) IN (?)", [params[:url], @normalized_url]).first
|
||||
end
|
||||
end
|
||||
|
||||
def save_recent_tags
|
||||
if @upload
|
||||
tags = Tag.scan_tags(@upload.tag_string)
|
||||
@@ -94,7 +66,7 @@ class UploadsController < ApplicationController
|
||||
permitted_params = %i[
|
||||
file source tag_string rating status parent_id artist_commentary_title
|
||||
artist_commentary_desc include_artist_commentary referer_url
|
||||
md5_confirmation as_pending
|
||||
md5_confirmation as_pending
|
||||
]
|
||||
|
||||
params.require(:upload).permit(permitted_params)
|
||||
|
||||
Reference in New Issue
Block a user