Browse Source

Change user backups to use expiring URLs for download when possible (#24136)

closed-social-glitch-2
Eugen Rochko 1 year ago
committed by GitHub
parent
commit
75e5a6e437
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 4 deletions
  1. +27
    -0
      app/controllers/backups_controller.rb
  2. +1
    -1
      app/models/backup.rb
  3. +1
    -1
      app/views/settings/exports/show.html.haml
  4. +1
    -1
      app/views/user_mailer/backup_ready.html.haml
  5. +1
    -1
      app/views/user_mailer/backup_ready.text.erb
  6. +1
    -0
      config/routes.rb

+ 27
- 0
app/controllers/backups_controller.rb View 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

+ 1
- 1
app/models/backup.rb View File

@ -18,6 +18,6 @@
class Backup < ApplicationRecord
belongs_to :user, inverse_of: :backups
has_attached_file :dump
has_attached_file :dump, s3_permissions: 'private'
validates_attachment_content_type :dump, content_type: /\Aapplication/
end

+ 1
- 1
app/views/settings/exports/show.html.haml View File

@ -64,6 +64,6 @@
%td= l backup.created_at
- if backup.processed?
%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
%td{ colspan: 2 }= t('exports.archive_takeout.in_progress')

+ 1
- 1
app/views/user_mailer/backup_ready.html.haml View File

@ -55,5 +55,5 @@
%tbody
%tr
%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'

+ 1
- 1
app/views/user_mailer/backup_ready.text.erb View File

@ -4,4 +4,4 @@
<%= t 'user_mailer.backup_ready.explanation' %>
=> <%= full_asset_url(@backup.dump.url) %>
=> <%= download_backup_url(@backup) %>

+ 1
- 0
config/routes.rb View File

@ -220,6 +220,7 @@ Rails.application.routes.draw do
resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]
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 :share, only: [:show, :create]

Loading…
Cancel
Save