mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
stream site download zip
This commit is contained in:
parent
d16bc0bace
commit
6c4a80123c
3 changed files with 19 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -218,9 +218,7 @@
|
|||
<% if !current_site.plan_feature(:no_file_restrictions) %>
|
||||
<a href="/site_files/allowed_types">Allowed file types</a> |
|
||||
<% end %>
|
||||
<% unless current_site.too_big_to_download? %>
|
||||
<a href="/site_files/<%= current_site.username %>.zip">Download entire site</a> |
|
||||
<% end %>
|
||||
<% unless is_education? %>
|
||||
<a href="/site_files/mount_info">Mount your site as a drive on your computer</a>
|
||||
<% end %>
|
||||
|
|
Loading…
Add table
Reference in a new issue