limit dl to 1 per hour

This commit is contained in:
Kyle Drake 2023-08-09 14:09:59 -05:00
parent 19050fea82
commit 9f96150b2d
2 changed files with 17 additions and 0 deletions

View file

@ -189,9 +189,17 @@ end
get '/site_files/:username.zip' do |username| get '/site_files/:username.zip' do |username|
require_login require_login
if !current_site.dl_queued_at.nil? && current_site.dl_queued_at > 1.hour.ago
flash[:error] = 'Site downloads are currently limited to once per hour, please try again later.'
redirect request.referer
end
content_type 'application/zip' content_type 'application/zip'
attachment "neocities-#{current_site.username}.zip" attachment "neocities-#{current_site.username}.zip"
current_site.dl_queued_at = Time.now
current_site.save_changes validate: false
directory_path = current_site.files_path directory_path = current_site.files_path
stream do |out| stream do |out|

View file

@ -0,0 +1,9 @@
Sequel.migration do
up {
DB.add_column :sites, :dl_queued_at, Time
}
down {
DB.drop_column :sites, :dl_queued_at
}
end