@@ -1052,40 +1052,47 @@ def conversations_path(params={})
10521052
10531053 # escape everything but slashes, see http://code.google.com/p/phusion-passenger/issues/detail?id=113
10541054 FILE_PATH_ESCAPE_PATTERN = Regexp . new ( "[^#{ URI ::PATTERN ::UNRESERVED } /]" )
1055- def safe_domain_file_url ( attachment , host = nil , verifier = nil , download = false ) # TODO: generalize this
1056- res = "#{ request . protocol } #{ host || HostUrl . file_host ( @domain_root_account || Account . default , request . host_with_port ) } "
1057- ts , sig = @current_user && @current_user . access_verifier
1058-
1059- # add parameters so that the other domain can create a session that
1060- # will authorize file access but not full app access. We need this in
1061- # case there are relative URLs in the file that point to other pieces
1062- # of content.
1063- opts = { :user_id => @current_user . try ( :id ) , :ts => ts , :sf_verifier => sig }
1064- opts [ :verifier ] = verifier if verifier . present?
1065-
1066- if download
1067- # download "for realz, dude" (see later comments about :download)
1068- opts [ :download_frd ] = 1
1069- else
1070- # don't set :download here, because file_download_url won't like it. see
1071- # comment below for why we'd want to set :download
1072- opts [ :inline ] = 1
1055+ def safe_domain_file_url ( attachment , host_and_shard = nil , verifier = nil , download = false ) # TODO: generalize this
1056+ if !host_and_shard
1057+ host_and_shard = HostUrl . file_host_with_shard ( @domain_root_account || Account . default , request . host_with_port )
10731058 end
1059+ host , shard = host_and_shard
1060+ res = "#{ request . protocol } #{ host } "
1061+
1062+ shard . activate do
1063+ ts , sig = @current_user && @current_user . access_verifier
1064+
1065+ # add parameters so that the other domain can create a session that
1066+ # will authorize file access but not full app access. We need this in
1067+ # case there are relative URLs in the file that point to other pieces
1068+ # of content.
1069+ opts = { :user_id => @current_user . try ( :id ) , :ts => ts , :sf_verifier => sig }
1070+ opts [ :verifier ] = verifier if verifier . present?
1071+
1072+ if download
1073+ # download "for realz, dude" (see later comments about :download)
1074+ opts [ :download_frd ] = 1
1075+ else
1076+ # don't set :download here, because file_download_url won't like it. see
1077+ # comment below for why we'd want to set :download
1078+ opts [ :inline ] = 1
1079+ end
10741080
1075- if @context && Attachment . relative_context? ( @context . class . base_ar_class ) && @context == attachment . context
1076- # so yeah, this is right. :inline=>1 wants :download=>1 to go along with
1077- # it, so we're setting :download=>1 *because* we want to display inline.
1078- opts [ :download ] = 1 unless download
1079-
1080- # if the context is one that supports relative paths (which requires extra
1081- # routes and stuff), then we'll build an actual named_context_url with the
1082- # params for show_relative
1083- res += named_context_url ( @context , :context_file_url , attachment )
1084- res += '/' + URI . escape ( attachment . full_display_path , FILE_PATH_ESCAPE_PATTERN )
1085- res += '?' + opts . to_query
1086- else
1087- # otherwise, just redirect to /files/:id
1088- res += file_download_url ( attachment , opts . merge ( :only_path => true ) )
1081+ if @context && Attachment . relative_context? ( @context . class . base_ar_class ) && @context == attachment . context
1082+ # so yeah, this is right. :inline=>1 wants :download=>1 to go along with
1083+ # it, so we're setting :download=>1 *because* we want to display inline.
1084+ opts [ :download ] = 1 unless download
1085+
1086+ # if the context is one that supports relative paths (which requires extra
1087+ # routes and stuff), then we'll build an actual named_context_url with the
1088+ # params for show_relative
1089+ res += named_context_url ( @context , :context_file_url , attachment )
1090+ res += '/' + URI . escape ( attachment . full_display_path , FILE_PATH_ESCAPE_PATTERN )
1091+ res += '?' + opts . to_query
1092+ else
1093+ # otherwise, just redirect to /files/:id
1094+ res += file_download_url ( attachment , opts . merge ( :only_path => true ) )
1095+ end
10891096 end
10901097
10911098 res
0 commit comments