fix for uploads with multiple directorys and same filenames

This commit is contained in:
Kyle Drake 2019-02-14 09:47:31 -08:00
parent f8697e50a6
commit 2c5ef5195b
2 changed files with 17 additions and 5 deletions

View file

@ -124,10 +124,7 @@ post '/site_files/upload' do
dir_name = params[:dir] if params[:dir]
unless params[:file_paths].nil? || params[:file_paths].empty? || params[:file_paths].length == 0
file_path = params[:file_paths].select {|file_path|
file[:filename] == Pathname(file_path).basename.to_s
}.first
file_path = params[:file_paths][i]
unless file_path.nil?
dir_name += '/' + Pathname(file_path).dirname.to_s
@ -161,7 +158,7 @@ post '/site_files/delete' do
require_login
path = HTMLEntities.new.decode params[:filename]
current_site.delete_file path
flash[:success] = "Deleted #{params[:filename]}. Please note it can take up to 30 minutes for deleted files to stop being viewable on your site."
flash[:success] = "Deleted #{params[:filename]}."
dirname = Pathname(path).dirname
dir_query = dirname.nil? || dirname.to_s == '.' ? '' : "?dir=#{Rack::Utils.escape dirname}"

View file

@ -213,6 +213,21 @@ describe 'site_files' do
PurgeCacheWorker.jobs.select {|j| j['args'].last == '/subdir/'}.length.must_equal 1
end
it 'succeeds with multiple files' do
upload(
'file_paths' => ['one/test.jpg', 'two/test.jpg'],
'files' => [
Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg'),
Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
]
)
@site.site_files.select {|s| s.path == 'one'}.length.must_equal 1
@site.site_files.select {|s| s.path == 'one/test.jpg'}.length.must_equal 1
@site.site_files.select {|s| s.path == 'two'}.length.must_equal 1
@site.site_files.select {|s| s.path == 'two/test.jpg'}.length.must_equal 1
end
it 'succeeds with valid file' do
initial_space_used = @site.space_used
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')