about summary refs log tree commit diff
path: root/app/controllers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2023-03-16 22:46:52 +0100
committerGitHub <noreply@github.com>2023-03-16 22:46:52 +0100
commit75e5a6e43738c278390c03c96d5d3e8575a2783c (patch)
treeefe4516b3260387ea192c851d1665d89d27dad77 /app/controllers
parentedc7ca5920641e938cb50c0bf49ff6b0c77a80b4 (diff)
Change user backups to use expiring URLs for download when possible (#24136)
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/backups_controller.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/app/controllers/backups_controller.rb b/app/controllers/backups_controller.rb
new file mode 100644
index 000000000..2f4b400b8
--- /dev/null
+++ b/app/controllers/backups_controller.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+class BackupsController < ApplicationController
+  include RoutingHelper
+
+  skip_before_action :require_functional!
+
+  before_action :authenticate_user!
+  before_action :set_backup
+
+  def download
+    case Paperclip::Attachment.default_options[:storage]
+    when :s3
+      redirect_to @backup.dump.expiring_url(10)
+    when :fog
+      redirect_to @backup.dump.expiring_url(Time.now.utc + 10)
+    when :filesystem
+      redirect_to full_asset_url(@backup.dump.url)
+    end
+  end
+
+  private
+
+  def set_backup
+    @backup = current_user.backups.find(params[:id])
+  end
+end