mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:10:46 -06:00
BUGFIX: 500 error on some invalid uploads
This commit is contained in:
parent
b329e23f85
commit
ca4c72e648
@ -16,8 +16,10 @@ class UploadsController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
return render_404 if !RailsMultisite::ConnectionManagement.has_db?(params[:site])
|
||||
|
||||
RailsMultisite::ConnectionManagement.with_connection(params[:site]) do |db|
|
||||
return render nothing: true, status: 404 unless Discourse.store.internal?
|
||||
return render_404 unless Discourse.store.internal?
|
||||
|
||||
id = params[:id].to_i
|
||||
url = request.fullpath
|
||||
@ -26,9 +28,15 @@ class UploadsController < ApplicationController
|
||||
if upload = Upload.find_by(id: id, url: url)
|
||||
send_file(Discourse.store.path_for(upload), filename: upload.original_filename)
|
||||
else
|
||||
render nothing: true, status: 404
|
||||
render_404
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def render_404
|
||||
render nothing: true, status: 404
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,13 +1,19 @@
|
||||
module RailsMultisite
|
||||
class ConnectionManagement
|
||||
CONFIG_FILE = 'config/multisite.yml'
|
||||
DEFAULT = 'default'.freeze
|
||||
|
||||
def self.has_db?(db)
|
||||
return true if db == DEFAULT
|
||||
(defined? @@db_spec_cache) && @@db_spec_cache && @@db_spec_cache[db]
|
||||
end
|
||||
|
||||
def self.rails4?
|
||||
!!(Rails.version =~ /^4/)
|
||||
end
|
||||
|
||||
def self.establish_connection(opts)
|
||||
if opts[:db] == "default" && (!defined?(@@default_spec) || !@@default_spec)
|
||||
if opts[:db] == DEFAULT && (!defined?(@@default_spec) || !@@default_spec)
|
||||
# don't do anything .. handled implicitly
|
||||
else
|
||||
spec = connection_spec(opts) || @@default_spec
|
||||
@ -119,33 +125,10 @@ module RailsMultisite
|
||||
|
||||
@@default_connection_handler = ActiveRecord::Base.connection_handler
|
||||
|
||||
# inject our connection_handler pool
|
||||
# WARNING MONKEY PATCH
|
||||
#
|
||||
# see: https://github.com/rails/rails/issues/8344#issuecomment-10800848
|
||||
if ActiveRecord::VERSION::MAJOR == 3
|
||||
ActiveRecord::Base.send :include, NewConnectionHandler
|
||||
ActiveRecord::Base.connection_handler = @@default_connection_handler
|
||||
end
|
||||
|
||||
@@connection_handlers = {}
|
||||
@@established_default = false
|
||||
end
|
||||
|
||||
module NewConnectionHandler
|
||||
def self.included(klass)
|
||||
klass.class_eval do
|
||||
define_singleton_method :connection_handler do
|
||||
Thread.current[:connection_handler] || @connection_handler
|
||||
end
|
||||
define_singleton_method :connection_handler= do |handler|
|
||||
@connection_handler ||= handler
|
||||
Thread.current[:connection_handler] = handler
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def initialize(app, config = nil)
|
||||
@app = app
|
||||
|
Loading…
Reference in New Issue
Block a user