diff --git a/app/site_files.rb b/app/site_files.rb index 6722388f..f5694d4b 100644 --- a/app/site_files.rb +++ b/app/site_files.rb @@ -189,15 +189,25 @@ end get '/site_files/:username.zip' do |username| require_login - if current_site.too_big_to_download? - flash[:error] = 'Cannot download site as zip as it is too large (or contains too many files)' - redirect '/dashboard' - end - - zipfile_path = current_site.files_zip - content_type 'application/octet-stream' + content_type 'application/zip' attachment "neocities-#{current_site.username}.zip" - send_file zipfile_path + + directory_path = current_site.files_path + + stream do |out| + ZipTricks::Streamer.open(out) do |zip| + Dir["#{directory_path}/**/*"].each do |file| + next if File.directory?(file) + + zip_path = file.sub("#{directory_path}/", '') + zip.write_deflated_file(zip_path) do |file_writer| + File.open(file, 'rb') do |file| + IO.copy_stream(file, file_writer) + end + end + end + end + end end get %r{\/site_files\/download\/(.+)} do diff --git a/models/site.rb b/models/site.rb index b0eff5cd..a0cc7290 100644 --- a/models/site.rb +++ b/models/site.rb @@ -83,8 +83,6 @@ class Site < Sequel::Model THUMBNAIL_RESOLUTIONS = ['210x158'] MAX_FILE_SIZE = 10**8 # 100 MB - MAX_SITE_DOWNLOAD_SIZE = 200_000_000 # 200MB - MAX_SITE_FILES_DOWNLOAD = 500 CLAMAV_THREAT_MATCHES = [ /^VBS/, @@ -1353,10 +1351,6 @@ class Site < Sequel::Model ((total_space_used.to_f / maximum_space) * 100).round(1) end - def too_big_to_download? - space_used > MAX_SITE_DOWNLOAD_SIZE || site_files_dataset.count > MAX_SITE_FILES_DOWNLOAD - end - # Note: Change Stat#prune! and the nginx map compiler if you change this business logic. def supporter? owner.plan_type != 'free' diff --git a/views/dashboard.erb b/views/dashboard.erb index 85f0e894..6d4b8a2e 100644 --- a/views/dashboard.erb +++ b/views/dashboard.erb @@ -218,9 +218,7 @@ <% if !current_site.plan_feature(:no_file_restrictions) %> Allowed file types | <% end %> - <% unless current_site.too_big_to_download? %> - Download entire site | - <% end %> + Download entire site | <% unless is_education? %> Mount your site as a drive on your computer <% end %>