2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

BUGFIX: attachments bust under multisite

This commit is contained in:
Sam 2014-03-25 10:37:31 +11:00
parent 14f7551f2b
commit 3830f41e5f
3 changed files with 26 additions and 16 deletions

View file

@ -30,17 +30,21 @@ class UploadsController < ApplicationController
end end
def show def show
return render nothing: true, status: 404 unless Discourse.store.internal? RailsMultisite::ConnectionManagement.with_connection(params[:site]) do |db|
id = params[:id].to_i return render nothing: true, status: 404 unless Discourse.store.internal?
url = request.fullpath
# the "url" parameter is here to prevent people from scanning the uploads using the id id = params[:id].to_i
upload = Upload.where(id: id, url: url).first url = request.fullpath
return render nothing: true, status: 404 unless upload # the "url" parameter is here to prevent people from scanning the uploads using the id
upload = Upload.where(id: id, url: url).first
send_file(Discourse.store.path_for(upload), filename: upload.original_filename) return render nothing: true, status: 404 unless upload
send_file(Discourse.store.path_for(upload), filename: upload.original_filename)
end
end end
end end

View file

@ -42,6 +42,14 @@ server {
# path to discourse's public directory # path to discourse's public directory
set $public /var/www/discourse/public; set $public /var/www/discourse/public;
# prep all possible needed proxy headers
# this is critical form multisite
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $thescheme;
location / { location / {
root $public; root $public;
@ -98,11 +106,6 @@ server {
} }
location @discourse { location @discourse {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $thescheme;
proxy_pass http://discourse; proxy_pass http://discourse;
} }

View file

@ -35,12 +35,15 @@ module RailsMultisite
old = current_db old = current_db
connected = ActiveRecord::Base.connection_pool.connected? connected = ActiveRecord::Base.connection_pool.connected?
establish_connection(:db => db) establish_connection(:db => db) unless connected && db == old
rval = yield db rval = yield db
ActiveRecord::Base.connection_handler.clear_active_connections!
establish_connection(:db => old) unless connected && db == old
ActiveRecord::Base.connection_handler.clear_active_connections! unless connected ActiveRecord::Base.connection_handler.clear_active_connections!
establish_connection(:db => old)
ActiveRecord::Base.connection_handler.clear_active_connections! unless connected
end
rval rval
end end