mirror of
https://github.com/neocities/neocities.git
synced 2025-07-21 01:56:03 +02:00
fixes for upload hash check, catch index.html delete scenario
This commit is contained in:
parent
61bf9012d6
commit
bf089379aa
2 changed files with 4 additions and 24 deletions
12
app/api.rb
12
app/api.rb
|
@ -7,17 +7,11 @@ end
|
|||
|
||||
post '/api/upload_hash' do
|
||||
require_api_credentials
|
||||
|
||||
res = {}
|
||||
|
||||
if params[:files].blank? || !params[:files].is_a?(Hash)
|
||||
api_error 400, 'no_file_hashes_provided', 'no file hashes provided'
|
||||
end
|
||||
|
||||
params[:files].each do |k,v|
|
||||
files = []
|
||||
params.each do |k,v|
|
||||
res[k] = current_site.sha1_hash_match? k, v
|
||||
end
|
||||
|
||||
api_success files: res
|
||||
end
|
||||
|
||||
|
@ -101,7 +95,7 @@ post '/api/delete' do
|
|||
api_error 400, 'missing_files', "#{path} was not found on your site, canceled deleting"
|
||||
end
|
||||
|
||||
if path == 'index.html'
|
||||
if path == 'index.html' || path == '/index.html'
|
||||
api_error 400, 'cannot_delete_index', 'you cannot delete your index.html file, canceled deleting'
|
||||
end
|
||||
|
||||
|
|
|
@ -233,26 +233,12 @@ describe 'api upload hash' do
|
|||
'test2.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
|
||||
post '/api/upload_hash', "files[test.jpg]" => test_hash, "files[test2.jpg]" => Digest::SHA1.hexdigest('herpderp')
|
||||
post '/api/upload_hash', "test.jpg" => test_hash, "test2.jpg" => Digest::SHA1.hexdigest('herpderp')
|
||||
|
||||
res[:result].must_equal 'success'
|
||||
res[:files][:'test.jpg'].must_equal true
|
||||
res[:files][:'test2.jpg'].must_equal false
|
||||
end
|
||||
|
||||
it 'throws error for missing data' do
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/upload_hash'
|
||||
res[:error_type].must_equal 'no_file_hashes_provided'
|
||||
end
|
||||
|
||||
it 'throws errors for weird data' do
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/upload_hash', 'files[]' => 'DUMPSTER FIRE'
|
||||
res[:error_type].must_equal 'no_file_hashes_provided'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'api upload' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue