mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 22:46:29 +08:00
FIX: make uploads safe for block that can run later
This commit is contained in:
parent
2b8d4508e5
commit
49f97d75b7
@ -6,6 +6,9 @@ class UploadsController < ApplicationController
|
|||||||
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required, only: [:show]
|
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required, only: [:show]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
# capture current user for block later on
|
||||||
|
me = current_user
|
||||||
|
|
||||||
# 50 characters ought to be enough for the upload type
|
# 50 characters ought to be enough for the upload type
|
||||||
type = params.require(:type).parameterize(separator: "_")[0..50]
|
type = params.require(:type).parameterize(separator: "_")[0..50]
|
||||||
|
|
||||||
@ -19,12 +22,12 @@ class UploadsController < ApplicationController
|
|||||||
for_private_message = params[:for_private_message] == "true"
|
for_private_message = params[:for_private_message] == "true"
|
||||||
|
|
||||||
if params[:synchronous] && (current_user.staff? || is_api?)
|
if params[:synchronous] && (current_user.staff? || is_api?)
|
||||||
data = create_upload(file, url, type, for_private_message, pasted)
|
data = create_upload(current_user, file, url, type, for_private_message, pasted)
|
||||||
render json: serialize_upload(data)
|
render json: serialize_upload(data)
|
||||||
else
|
else
|
||||||
Scheduler::Defer.later("Create Upload") do
|
Scheduler::Defer.later("Create Upload") do
|
||||||
begin
|
begin
|
||||||
data = create_upload(file, url, type, for_private_message, pasted)
|
data = create_upload(me, file, url, type, for_private_message, pasted)
|
||||||
ensure
|
ensure
|
||||||
MessageBus.publish("/uploads/#{type}", serialize_upload(data), client_ids: [params[:client_id]])
|
MessageBus.publish("/uploads/#{type}", serialize_upload(data), client_ids: [params[:client_id]])
|
||||||
end
|
end
|
||||||
@ -80,7 +83,7 @@ class UploadsController < ApplicationController
|
|||||||
raise Discourse::NotFound
|
raise Discourse::NotFound
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_upload(file, url, type, for_private_message, pasted)
|
def create_upload(current_user, file, url, type, for_private_message, pasted)
|
||||||
if file.nil?
|
if file.nil?
|
||||||
if url.present? && is_api?
|
if url.present? && is_api?
|
||||||
maximum_upload_size = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes
|
maximum_upload_size = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user