mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
Merge branch 'master' into api
This commit is contained in:
commit
32f50916fa
2 changed files with 17 additions and 9 deletions
9
app.rb
9
app.rb
|
@ -285,14 +285,9 @@ post '/site_files/upload' do
|
|||
end
|
||||
|
||||
sanitized_filename = params[:newfile][:filename].gsub(/[^a-zA-Z0-9_\-.]/, '')
|
||||
|
||||
current_site.store_file sanitized_filename, params[:newfile][:tempfile]
|
||||
|
||||
if sanitized_filename =~ /index\.html/
|
||||
ScreenshotWorker.perform_async current_site.username
|
||||
current_site.update site_changed: true
|
||||
end
|
||||
|
||||
current_site.update changed_count: 1+current_site.changed_count, updated_at: Time.now
|
||||
current_site.increment_changed_count
|
||||
|
||||
flash[:success] = "Successfully uploaded file #{sanitized_filename}."
|
||||
redirect '/dashboard'
|
||||
|
|
|
@ -136,6 +136,18 @@ class Site < Sequel::Model
|
|||
def store_file(filename, uploaded)
|
||||
FileUtils.mv uploaded.path, file_path(filename)
|
||||
File.chmod(0640, file_path(filename))
|
||||
|
||||
if filename =~ /index\.html/
|
||||
ScreenshotWorker.perform_async values[:username]
|
||||
self.site_changed = true
|
||||
save(validate: false)
|
||||
end
|
||||
end
|
||||
|
||||
def increment_changed_count
|
||||
self.changed_count += 1
|
||||
self.updated_at = Time.now
|
||||
save(validate: false)
|
||||
end
|
||||
|
||||
def files_zip
|
||||
|
@ -199,11 +211,12 @@ class Site < Sequel::Model
|
|||
errors.add :over_capacity, 'We are currently at capacity, and cannot create your home page. We will fix this shortly. Please come back later and try again, our apologies.'
|
||||
end
|
||||
|
||||
if !values[:username].match(VALID_HOSTNAME)
|
||||
# TODO regex fails for usernames <= 2 chars, tempfix for now.
|
||||
if new? && values[:username].length > 2 && !values[:username].match(VALID_HOSTNAME)
|
||||
errors.add :username, 'A valid user/site name is required.'
|
||||
end
|
||||
|
||||
if values[:username].length > 32
|
||||
if new? && values[:username].length > 32
|
||||
errors.add :username, 'User/site name cannot exceed 32 characters.'
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue