mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
site changed to false for empty index files
This commit is contained in:
parent
4447d24ed3
commit
ff953f4c09
3 changed files with 17 additions and 1 deletions
|
@ -74,6 +74,8 @@ class Site < Sequel::Model
|
|||
/PHP\.Hide/
|
||||
]
|
||||
|
||||
EMPTY_FILE_HASH = Digest::SHA1.hexdigest ''
|
||||
|
||||
PHISHING_FORM_REGEX = /www.formbuddy.com\/cgi-bin\/form.pl/i
|
||||
SPAM_MATCH_REGEX = ENV['RACK_ENV'] == 'test' ? /pillz/ : /#{$config['spam_smart_filter'].join('|')}/i
|
||||
EMAIL_SANITY_REGEX = /.+@.+\..+/i
|
||||
|
@ -1177,6 +1179,10 @@ class Site < Sequel::Model
|
|||
end
|
||||
end
|
||||
|
||||
def empty_index?
|
||||
!site_files_dataset.where(path: /^\/?index.html$/).where(sha1_hash: EMPTY_FILE_HASH).first.nil?
|
||||
end
|
||||
|
||||
# array of hashes: filename, tempfile, opts.
|
||||
def store_files(files, opts={})
|
||||
results = []
|
||||
|
@ -1206,12 +1212,14 @@ class Site < Sequel::Model
|
|||
end
|
||||
|
||||
if results.include? true && opts[:new_install] != true
|
||||
if files.select {|f| f[:filename] =~ /^\/?index.html$/}.length > 0 || site_changed == true
|
||||
if((files.select {|f| f[:filename] =~ /^\/?index.html$/}.length > 0 || site_changed == true))
|
||||
index_changed = true
|
||||
else
|
||||
index_changed = false
|
||||
end
|
||||
|
||||
index_changed = false if empty_index?
|
||||
|
||||
time = Time.now
|
||||
sql = DB["update sites set site_changed=?, site_updated_at=?, updated_at=?, changed_count=changed_count+1, space_used=space_used#{new_size < 0 ? new_size.to_s : '+'+new_size.to_s} where id=?",
|
||||
index_changed,
|
||||
|
|
0
tests/files/blankindex/index.html
Normal file
0
tests/files/blankindex/index.html
Normal file
|
@ -188,6 +188,14 @@ describe 'site_files' do
|
|||
@site.site_changed.must_equal false
|
||||
end
|
||||
|
||||
it 'sets site changed to false if index is empty' do
|
||||
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/blankindex/index.html', 'text/html')
|
||||
upload 'files[]' => uploaded_file
|
||||
last_response.body.must_match /successfully uploaded/i
|
||||
@site.empty_index?.must_equal true
|
||||
@site.site_changed.must_equal false
|
||||
end
|
||||
|
||||
it 'fails with unsupported file' do
|
||||
upload 'files[]' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
||||
last_response.body.must_match /only supported by.+supporter account/i
|
||||
|
|
Loading…
Add table
Reference in a new issue