editor: use regex for path to match dirs, improve perf

This commit is contained in:
Kyle Drake 2016-07-20 10:52:19 -07:00
parent 21299e3abc
commit 32ddc97a95
2 changed files with 13 additions and 10 deletions

View file

@ -152,11 +152,12 @@ get '/site_files/:username.zip' do |username|
send_file zipfile_path
end
get '/site_files/download/:filename' do |filename|
get %r{\/site_files\/download\/(.+)} do
require_login
content_type 'application/octet-stream'
not_found if params[:captures].nil? || params[:captures].length != 1
filename = params[:captures].first
attachment filename
current_site.get_file filename
send_file current_site.current_files_path(filename)
end
get %r{\/site_files\/text_editor\/(.+)} do
@ -174,16 +175,18 @@ get %r{\/site_files\/text_editor\/(.+)} do
nil
end
begin
@file_data = current_site.get_file @filename
rescue Errno::ENOENT
flash[:error] = 'We could not find the requested file.'
redirect '/dashboard'
rescue Errno::EISDIR
file_path = current_site.current_files_path @filename
if File.directory? file_path
flash[:error] = 'Cannot edit a directory.'
redirect '/dashboard'
end
if !File.exist?(file_path)
flash[:error] = 'We could not find the requested file.'
redirect '/dashboard'
end
@title = "Editing #{@filename}"
erb :'site_files/text_editor'

View file

@ -120,7 +120,7 @@
if(unsavedChanges == false)
return
$.ajax({
url: '/site_files/save/<%= @filename %>?csrf_token=<%= Rack::Utils.escape csrf_token %>',
url: "/site_files/save/<%= Addressable::URI.encode @filename %>?csrf_token=<%= Rack::Utils.escape csrf_token %>",
data: editor.getValue(),
processData: false,
contentType: false,