Change user backups to use expiring URLs for download when possible (#24136)
This commit is contained in:
parent
3e9978071b
commit
a6217bd035
6 changed files with 32 additions and 4 deletions
27
app/controllers/backups_controller.rb
Normal file
27
app/controllers/backups_controller.rb
Normal file
|
@ -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
|
|
@ -17,6 +17,6 @@
|
||||||
class Backup < ApplicationRecord
|
class Backup < ApplicationRecord
|
||||||
belongs_to :user, inverse_of: :backups
|
belongs_to :user, inverse_of: :backups
|
||||||
|
|
||||||
has_attached_file :dump
|
has_attached_file :dump, s3_permissions: 'private'
|
||||||
do_not_validate_attachment_file_type :dump
|
do_not_validate_attachment_file_type :dump
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,6 +64,6 @@
|
||||||
%td= l backup.created_at
|
%td= l backup.created_at
|
||||||
- if backup.processed?
|
- if backup.processed?
|
||||||
%td= number_to_human_size backup.dump_file_size
|
%td= number_to_human_size backup.dump_file_size
|
||||||
%td= table_link_to 'download', t('exports.archive_takeout.download'), backup.dump.url
|
%td= table_link_to 'download', t('exports.archive_takeout.download'), download_backup_url(backup)
|
||||||
- else
|
- else
|
||||||
%td{ colspan: 2 }= t('exports.archive_takeout.in_progress')
|
%td{ colspan: 2 }= t('exports.archive_takeout.in_progress')
|
||||||
|
|
|
@ -55,5 +55,5 @@
|
||||||
%tbody
|
%tbody
|
||||||
%tr
|
%tr
|
||||||
%td.button-primary
|
%td.button-primary
|
||||||
= link_to full_asset_url(@backup.dump.url) do
|
= link_to download_backup_url(@backup) do
|
||||||
%span= t 'exports.archive_takeout.download'
|
%span= t 'exports.archive_takeout.download'
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
|
|
||||||
<%= t 'user_mailer.backup_ready.explanation' %>
|
<%= t 'user_mailer.backup_ready.explanation' %>
|
||||||
|
|
||||||
=> <%= full_asset_url(@backup.dump.url) %>
|
=> <%= download_backup_url(@backup) %>
|
||||||
|
|
|
@ -219,6 +219,7 @@ Rails.application.routes.draw do
|
||||||
resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]
|
resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]
|
||||||
|
|
||||||
get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy, format: false
|
get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy, format: false
|
||||||
|
get '/backups/:id/download', to: 'backups#download', as: :download_backup, format: false
|
||||||
|
|
||||||
resource :authorize_interaction, only: [:show, :create]
|
resource :authorize_interaction, only: [:show, :create]
|
||||||
resource :share, only: [:show, :create]
|
resource :share, only: [:show, :create]
|
||||||
|
|
Loading…
Reference in a new issue