mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
editor: use regex for path to match dirs, improve perf
This commit is contained in:
parent
21299e3abc
commit
32ddc97a95
2 changed files with 13 additions and 10 deletions
|
@ -152,11 +152,12 @@ get '/site_files/:username.zip' do |username|
|
||||||
send_file zipfile_path
|
send_file zipfile_path
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/site_files/download/:filename' do |filename|
|
get %r{\/site_files\/download\/(.+)} do
|
||||||
require_login
|
require_login
|
||||||
content_type 'application/octet-stream'
|
not_found if params[:captures].nil? || params[:captures].length != 1
|
||||||
|
filename = params[:captures].first
|
||||||
attachment filename
|
attachment filename
|
||||||
current_site.get_file filename
|
send_file current_site.current_files_path(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
get %r{\/site_files\/text_editor\/(.+)} do
|
get %r{\/site_files\/text_editor\/(.+)} do
|
||||||
|
@ -174,16 +175,18 @@ get %r{\/site_files\/text_editor\/(.+)} do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
file_path = current_site.current_files_path @filename
|
||||||
@file_data = current_site.get_file @filename
|
|
||||||
rescue Errno::ENOENT
|
if File.directory? file_path
|
||||||
flash[:error] = 'We could not find the requested file.'
|
|
||||||
redirect '/dashboard'
|
|
||||||
rescue Errno::EISDIR
|
|
||||||
flash[:error] = 'Cannot edit a directory.'
|
flash[:error] = 'Cannot edit a directory.'
|
||||||
redirect '/dashboard'
|
redirect '/dashboard'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if !File.exist?(file_path)
|
||||||
|
flash[:error] = 'We could not find the requested file.'
|
||||||
|
redirect '/dashboard'
|
||||||
|
end
|
||||||
|
|
||||||
@title = "Editing #{@filename}"
|
@title = "Editing #{@filename}"
|
||||||
|
|
||||||
erb :'site_files/text_editor'
|
erb :'site_files/text_editor'
|
||||||
|
|
|
@ -120,7 +120,7 @@
|
||||||
if(unsavedChanges == false)
|
if(unsavedChanges == false)
|
||||||
return
|
return
|
||||||
$.ajax({
|
$.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(),
|
data: editor.getValue(),
|
||||||
processData: false,
|
processData: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
|
|
Loading…
Add table
Reference in a new issue