mirror of
https://github.com/neocities/neocities.git
synced 2025-07-23 11:06:02 +02:00
file saving
This commit is contained in:
parent
44d785e222
commit
f4ce6c9994
2 changed files with 54 additions and 3 deletions
19
app.rb
19
app.rb
|
@ -150,9 +150,28 @@ end
|
|||
|
||||
get '/site_files/text_editor/:filename' do |filename|
|
||||
@file_url = "http://#{current_site.username}.neocities.org/#{filename}"
|
||||
|
||||
slim :'site_files/text_editor'
|
||||
end
|
||||
|
||||
post '/site_files/save/:filename' do |filename|
|
||||
tmpfile = Tempfile.new 'neocities_saving_file'
|
||||
|
||||
if (tmpfile.size + current_site.total_space) > Site::MAX_SPACE
|
||||
halt 'File is too large, it has NOT been saved. Please make a local copy and then try to reduce the size.'
|
||||
end
|
||||
|
||||
tmpfile.write request.body.read
|
||||
tmpfile.close
|
||||
|
||||
sanitized_filename = filename.gsub(/[^a-zA-Z_\-.]/, '')
|
||||
dest_path = File.join site_base_path(current_site.username), sanitized_filename
|
||||
|
||||
FileUtils.mv tmpfile.path, dest_path
|
||||
File.chmod(0640, dest_path) if self.class.production?
|
||||
'ok'
|
||||
end
|
||||
|
||||
get '/terms' do
|
||||
slim :'terms'
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue