lato_storage 3.1.3 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68d3ea583748a22788534d655f215020a2e4f77aa2a2de7ee17324dfa4d6613e
4
- data.tar.gz: 6437297304971083309daaa39535a0f03c65cef445708b9a53b4924fbafc32d3
3
+ metadata.gz: 34f83f29f3176d4dc99f946215373c37a4a47a509af4aaff44d7a4f49ea89af6
4
+ data.tar.gz: 4e63b760003ef1a5a70a84bb9e4ba34cf658b9a0708149b4c788db578e1a4703
5
5
  SHA512:
6
- metadata.gz: 2b8c97308770e9a9ba9685dc876399ca692fb1988f00c9086f5c97a6357ce835c74eeb2defa84aa7f2631049e1cf88cce56eb2e77eaac317f87ef82ebe20622d
7
- data.tar.gz: 266fe35e267ca803dc9e85a68da009fd18632b4cae0afa446cb5baf9b6001506b3a090e64da1cca95c94933ecbf8fe637af7fd688ccbac425f77e6493af6d1ff
6
+ metadata.gz: 820c2c59648c64f611706f760850eafb22f579fb7556a8807f15455f45b778147eea96d78def8484895870179647091ac8f0ca2086419d49c68dcaf748876aa1
7
+ data.tar.gz: d340386f6886a4629e4c022c7415eb474836895befe4289934490eab3cb654123a46d6af7e655037fea0405864d6d2d8ce61aa717d434f4ae5ec33cb4138bf2c
data/README.md CHANGED
@@ -5,7 +5,7 @@ NOTE: This gem is using [Active Storage Dashboard](https://github.com/giovapanas
5
5
 
6
6
  ## Installation
7
7
 
8
- Requires Rails 8.1.3.1 or newer in the 8.1 series and Lato 3.25.0 or newer. Existing applications must install the new Lato session migration before deployment; previous sessions are invalidated.
8
+ Requires Rails 8.1.3.1 or newer in the 8.1 series, Lato 3.25.0 or newer and Active Storage installed on the host application (`rails active_storage:install`). Applications using variants with vips require libvips 8.13 or newer. Existing applications must install the new Lato session migration before deployment; previous sessions are invalidated.
9
9
  Add required dependencies to your application's Gemfile:
10
10
 
11
11
  ```ruby
@@ -18,7 +18,6 @@ Install gem and run required tasks:
18
18
 
19
19
  ```bash
20
20
  $ bundle
21
- $ rails lato_storage:install:application
22
21
  $ rails lato_storage:install:migrations
23
22
  $ rails db:migrate
24
23
  ```
@@ -33,7 +32,7 @@ Rails.application.routes.draw do
33
32
  end
34
33
  ```
35
34
 
36
- Import Lato Scss on **app/assets/stylesheets/application.scss** file:
35
+ Import Lato Storage Scss on **app/assets/stylesheets/application.scss** file:
37
36
  ```scss
38
37
  @import 'lato_storage/application';
39
38
 
@@ -47,6 +46,87 @@ import "lato_storage/application";
47
46
  // ....
48
47
  ```
49
48
 
49
+ Add a menu entry in the host application navbar or sidebar partials (`app/views/layouts/lato/_navbar-nav_content.html.erb` or `_sidebar-nav_content.html.erb`):
50
+
51
+ ```erb
52
+ <% if @session.user&.lato_storage_admin %>
53
+ <%= lato_sidebar_nav_item :lato_storage, lato_storage.root_path do %>
54
+ <i class="bi bi-hdd me-2"></i> Storage
55
+ <% end %>
56
+ <% end %>
57
+ ```
58
+
59
+ (`rails lato_storage:install:application` is a no-op kept for compatibility: it is not required.)
60
+
61
+ ## Permissions
62
+
63
+ Access requires a Lato session and the `lato_storage_admin` flag on `Lato::User` (added by `rails lato_storage:install:migrations`). Other users are redirected with an alert.
64
+
65
+ ```ruby
66
+ Lato::User.find_by(email: "admin@example.com").update!(lato_storage_admin: true)
67
+ ```
68
+
69
+ **The flag grants visibility on the files of every model, user and group** (including `lato_spaces` groups): filename, record reference and a download link. Give it only to super admins.
70
+
71
+ ## Features and routes
72
+
73
+ Routes are relative to the mount path (`/lato-storage`):
74
+
75
+ - `GET /`: dashboard (blobs, attachments, variants, deletable blobs, total and average storage, content type distribution, 3 largest blobs).
76
+ - `GET /blobs`, `GET /attachments`, `GET /variant_records`: searchable, sortable, paginated lists.
77
+ - `POST /cleaner`: starts the cleanup (see below).
78
+
79
+ Links to files are signed, forced as download and expire after `blob_url_expires_in` (default 12 hours).
80
+
81
+ ## Configuration
82
+
83
+ ```ruby
84
+ LatoStorage.configure do |config|
85
+ config.optimize_performances = true
86
+ config.blob_url_expires_in = 12.hours
87
+ end
88
+ ```
89
+
90
+ With `optimize_performances = true`:
91
+
92
+ - blobs, attachments and variants counts are estimates (`TABLE_ROWS` on MySQL, `reltuples` on PostgreSQL, exact `count` on other databases);
93
+ - total storage and content types are extrapolated from a sample of the last 5000 blobs;
94
+ - the "largest blobs" card is hidden and lists skip the total count;
95
+ - the dashboard data is cached for 12 hours and shows the "updated at" time.
96
+
97
+ With `false` (default) every dashboard visit runs the queries synchronously: exact values, but slow on large tables.
98
+
99
+ ### PreloadDashboardDataJob
100
+
101
+ With optimization enabled, `LatoStorage::PreloadDashboardDataJob` computes and caches the dashboard data (data TTL 12 hours, lock TTL 30 minutes). Requirements and behavior:
102
+
103
+ - `Rails.cache` must be a store shared between web and worker processes (not `:null_store`, `:memory_store` or per-process `:file_store`), and a real Active Job queue adapter is needed for the background refresh.
104
+ - The first visit without cache computes the data synchronously. While a calculation is running the dashboard shows zeroed values with a "computing" notice; if it fails it shows an error notice.
105
+ - Pre-warm it with a recurring job, for example with Solid Queue (`config/recurring.yml`):
106
+
107
+ ```yaml
108
+ production:
109
+ lato_storage_preload:
110
+ class: LatoStorage::PreloadDashboardDataJob
111
+ args: [true]
112
+ schedule: every 6 hours
113
+ ```
114
+
115
+ ## Cleanup
116
+
117
+ The "Free up space" button asks confirmation and starts `POST /cleaner`, which runs `Lato::ActiveStorageCleanerJob` (from `lato`) as a Lato operation.
118
+
119
+ - It calls `purge_later` on every blob **without attachments created more than 12 hours ago**: an Active Job worker is required and the deletion is **irreversible**.
120
+ - Blobs referenced only by id in custom columns or JSON are considered orphans too.
121
+ - Empty folders of a local disk service are removed.
122
+ - Only one cleanup per 10 minutes can be started (cache lock, same shared cache requirement as above).
123
+
124
+ Headless run: `Lato::Operation.generate("Lato::ActiveStorageCleanerJob", {}, user_id).start`.
125
+
126
+ ## Security notes
127
+
128
+ Keep the Rails defaults for `config.active_storage.content_types_to_serve_as_binary` and `content_types_allowed_inline`: if HTML or SVG files uploaded by users were served inline, opening a link from the list would run them on the admin origin.
129
+
50
130
  ## Development
51
131
 
52
132
  Clone repository, install dependencies, run migrations and start:
@@ -57,9 +137,11 @@ $ cd lato_storage
57
137
  $ bundle
58
138
  $ rails db:migrate
59
139
  $ rails db:seed
60
- $ foreman start -f Procfile.dev
140
+ $ rails server
61
141
  ```
62
142
 
143
+ The dummy app is mounted at `/lato-storage`. `rails db:seed` creates the development user `admin@mail.com` / `Password1!` (dummy only).
144
+
63
145
  ## Publish
64
146
 
65
147
  ```shell
@@ -1 +1 @@
1
- console.log("Lato Settings JS loaded");
1
+ // Lato Storage JS (no behaviors yet)
@@ -5,23 +5,15 @@ module LatoStorage
5
5
  before_action :authenticate_lato_storage_admin
6
6
  before_action { active_sidebar(:lato_storage); active_navbar(:lato_storage) }
7
7
 
8
+ CLEANER_LOCK_CACHE_KEY = 'LatoStorage::ApplicationController/cleaner_lock'
9
+
8
10
  def index
9
- # @blobs_count = ActiveStorage::Blob.count
10
- # @attachments_count = ActiveStorage::Attachment.count
11
- # @variant_records_count = defined?(ActiveStorage::VariantRecord) ? ActiveStorage::VariantRecord.count : 0
12
- # @deletable_blobs_count = ActiveStorage::Blob.unattached.where('active_storage_blobs.created_at < ?', 12.hours.ago).count
13
-
14
- # @total_storage = ActiveStorage::Blob.sum(:byte_size)
15
- # @avg_storage = @total_storage / @blobs_count if @blobs_count.positive?
16
-
17
- # @content_types = ActiveStorage::Blob.group(:content_type).count.sort_by { |_, count| -count }.first(5)
18
-
19
- # @largest_blobs = ActiveStorage::Blob.order(byte_size: :desc).limit(3)
20
-
21
11
  @data = LatoStorage::PreloadDashboardDataJob.perform_now
22
12
  end
23
13
 
24
14
  def cleaner
15
+ return cleaner_rejected(:cleaner_already_running, :conflict) unless acquire_cleaner_lock
16
+
25
17
  @operation = Lato::Operation.generate('Lato::ActiveStorageCleanerJob', {}, @session.user_id)
26
18
 
27
19
  respond_to do |format|
@@ -29,7 +21,8 @@ module LatoStorage
29
21
  format.html { redirect_to lato.operation_path(@operation) }
30
22
  format.json { render json: @operation }
31
23
  else
32
- format.html { render :index, status: :unprocessable_entity }
24
+ Rails.cache.delete(CLEANER_LOCK_CACHE_KEY)
25
+ format.html { redirect_to lato_storage.root_path, alert: I18n.t('lato_storage.cleaner_failed') }
33
26
  format.json { render json: @operation.errors, status: :unprocessable_entity }
34
27
  end
35
28
  end
@@ -40,7 +33,22 @@ module LatoStorage
40
33
  def authenticate_lato_storage_admin
41
34
  return true if @session.user&.lato_storage_admin
42
35
 
43
- redirect_to lato.root_path, alert: 'You have not access to this section.'
36
+ respond_to do |format|
37
+ format.html { redirect_to lato.root_path, alert: I18n.t('lato_storage.access_denied') }
38
+ format.json { head :forbidden }
39
+ end
40
+ end
41
+
42
+ # The operation runs in background and its end is unknown here, so the lock simply expires
43
+ def acquire_cleaner_lock
44
+ Rails.cache.write(CLEANER_LOCK_CACHE_KEY, true, expires_in: 10.minutes, unless_exist: true)
45
+ end
46
+
47
+ def cleaner_rejected(message_key, status)
48
+ respond_to do |format|
49
+ format.html { redirect_to lato_storage.root_path, alert: I18n.t("lato_storage.#{message_key}") }
50
+ format.json { render json: { error: I18n.t("lato_storage.#{message_key}") }, status: status }
51
+ end
44
52
  end
45
53
  end
46
54
  end
@@ -2,13 +2,13 @@ module LatoStorage
2
2
  class VariantRecordsController < ApplicationController
3
3
  def index
4
4
  unless defined?(ActiveStorage::VariantRecord)
5
- flash[:alert] = 'ActiveStorage::VariantRecord is not available in this version of Rails.'
5
+ flash[:alert] = I18n.t('lato_storage.variant_records_unavailable')
6
6
  redirect_to lato_storage.root_path
7
7
  return
8
8
  end
9
9
 
10
10
  columns = %i[id blob_id variation_digest]
11
- sortable_columns = %i[]
11
+ sortable_columns = %i[blob_id]
12
12
  searchable_columns = %i[id blob_id]
13
13
 
14
14
  @variant_records = lato_index_collection(
@@ -1,15 +1,13 @@
1
1
  module LatoStorage
2
2
  module ApplicationHelper
3
-
4
3
  def format_bytes(bytes)
5
- return '0 B' if bytes.nil? || bytes == 0
6
-
7
- units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
8
- exponent = (Math.log(bytes) / Math.log(1024)).to_i
9
- exponent = [exponent, units.size - 1].min
10
-
11
- converted = bytes.to_f / (1024 ** exponent)
12
- "#{format('%.2f', converted)} #{units[exponent]}"
4
+ number_to_human_size(bytes.to_i)
5
+ end
6
+
7
+ def format_datetime(time)
8
+ return '-' if time.nil?
9
+
10
+ I18n.l(time, format: I18n.t('lato_storage.datetime_format'))
13
11
  end
14
12
 
15
13
  def active_storage_blob_byte_size(blob)
@@ -17,15 +15,15 @@ module LatoStorage
17
15
  end
18
16
 
19
17
  def active_storage_blob_created_at(blob)
20
- blob.created_at.strftime('%Y-%m-%d %H:%M:%S')
18
+ format_datetime blob.created_at
21
19
  end
22
20
 
23
21
  def active_storage_blob_filename(blob)
24
- link_to blob.filename, main_app.url_for(blob), target: '_blank', class: 'text-truncate d-block', style: 'max-width: 250px;'
22
+ active_storage_blob_link(blob)
25
23
  end
26
24
 
27
25
  def active_storage_attachment_created_at(attachment)
28
- attachment.created_at.strftime('%Y-%m-%d %H:%M:%S')
26
+ format_datetime attachment.created_at
29
27
  end
30
28
 
31
29
  def active_storage_attachment_record_id(attachment)
@@ -33,13 +31,23 @@ module LatoStorage
33
31
  end
34
32
 
35
33
  def active_storage_attachment_blob_id(attachment)
36
- return ' - ' if attachment.blob.nil?
37
- link_to attachment.blob.filename, main_app.url_for(attachment.blob), target: '_blank', class: 'text-truncate d-block', style: 'max-width: 250px;'
34
+ active_storage_blob_link(attachment.blob)
38
35
  end
39
36
 
40
37
  def active_storage_variant_record_blob_id(variant_record)
41
- return ' - ' if variant_record.blob.nil?
42
- link_to variant_record.blob.filename, main_app.url_for(variant_record.blob), target: '_blank', class: 'text-truncate d-block', style: 'max-width: 250px;'
38
+ active_storage_blob_link(variant_record.blob)
39
+ end
40
+
41
+ private
42
+
43
+ # Expiring link, forced as download, so a file uploaded by someone else is never rendered inline on the admin origin.
44
+ def active_storage_blob_link(blob)
45
+ return ' - ' if blob.nil?
46
+
47
+ url = main_app.rails_blob_path(blob, expires_in: LatoStorage.config.blob_url_expires_in, disposition: 'attachment')
48
+ link_to url, target: '_blank', rel: 'noopener noreferrer', title: blob.filename.to_s, class: 'text-truncate d-block', style: 'max-width: 250px;' do
49
+ safe_join([blob.filename.to_s, tag.span(I18n.t('lato_storage.new_tab'), class: 'visually-hidden')], ' ')
50
+ end
43
51
  end
44
52
  end
45
53
  end
@@ -3,26 +3,49 @@ module LatoStorage
3
3
  SEMAPHORE_CACHE_KEY = 'LatoStorage::PreloadDashboardDataJob/semaphore'
4
4
  DATA_CACHE_KEY = 'LatoStorage::PreloadDashboardDataJob/data'
5
5
 
6
+ # Returns always a complete data hash, so the view can render even when data is missing.
7
+ # Keys `computing` (data not ready yet) and `error` (calculation failed) explain a zeroed dashboard.
6
8
  def perform(force_execution = false)
7
9
  return load_data_without_optimizations unless LatoStorage.config.optimize_performances
8
-
10
+
9
11
  data = Rails.cache.read(DATA_CACHE_KEY)
10
- return data || {} if Rails.cache.read(SEMAPHORE_CACHE_KEY)
12
+ return data || default_data(computing: true) if Rails.cache.read(SEMAPHORE_CACHE_KEY)
11
13
 
12
14
  if data && !force_execution
13
15
  LatoStorage::PreloadDashboardDataJob.perform_later(true)
14
16
  return data
15
17
  end
16
18
 
17
- Rails.cache.write(SEMAPHORE_CACHE_KEY, true, expires_in: 30.minutes)
18
- data = load_data_with_optimizations
19
- Rails.cache.write(DATA_CACHE_KEY, data, expires_in: 12.hours)
20
- return data
19
+ # Atomic lock: only one process computes the data at a time
20
+ return data || default_data(computing: true) unless Rails.cache.write(SEMAPHORE_CACHE_KEY, true, expires_in: 30.minutes, unless_exist: true)
21
+
22
+ begin
23
+ data = load_data_with_optimizations
24
+ Rails.cache.write(DATA_CACHE_KEY, data, expires_in: 12.hours)
25
+ data
26
+ ensure
27
+ Rails.cache.delete(SEMAPHORE_CACHE_KEY)
28
+ end
21
29
  rescue StandardError => e
22
30
  Rails.logger.error "Error in LatoStorage::PreloadDashboardDataJob: #{e.message}"
23
31
  Rails.logger.error e.backtrace.join("\n")
24
- Rails.cache.delete(SEMAPHORE_CACHE_KEY)
25
- nil
32
+ default_data(error: true)
33
+ end
34
+
35
+ def default_data(computing: false, error: false)
36
+ {
37
+ blobs_count: 0,
38
+ attachments_count: 0,
39
+ variant_records_count: 0,
40
+ deletable_blobs_count: 0,
41
+ total_storage: 0,
42
+ avg_storage: 0,
43
+ content_types: [],
44
+ largest_blobs: [],
45
+ generated_at: nil,
46
+ computing: computing,
47
+ error: error
48
+ }
26
49
  end
27
50
 
28
51
  private
@@ -49,7 +72,7 @@ module LatoStorage
49
72
  content_type: blob.content_type,
50
73
  service_name: blob.service_name,
51
74
  checksum: blob.checksum,
52
- url: Rails.application.routes.url_helpers.rails_blob_url(blob, only_path: true, expires_in: 12.hours)
75
+ url: Rails.application.routes.url_helpers.rails_blob_path(blob, expires_in: LatoStorage.config.blob_url_expires_in, disposition: 'attachment')
53
76
  }
54
77
  end
55
78
 
@@ -61,7 +84,10 @@ module LatoStorage
61
84
  total_storage: total_storage,
62
85
  avg_storage: avg_storage,
63
86
  content_types: content_types,
64
- largest_blobs: largest_blobs
87
+ largest_blobs: largest_blobs,
88
+ generated_at: Time.current,
89
+ computing: false,
90
+ error: false
65
91
  }
66
92
  end
67
93
 
@@ -76,7 +102,7 @@ module LatoStorage
76
102
  deletable_blobs_count = deletable_blobs_count_loader
77
103
  total_storage = total_storage_loader(blobs_count)
78
104
  avg_storage = blobs_count.positive? ? total_storage / blobs_count : 0
79
- content_types = content_types_loader
105
+ content_types = content_types_loader(blobs_count)
80
106
 
81
107
  {
82
108
  blobs_count: blobs_count,
@@ -86,7 +112,10 @@ module LatoStorage
86
112
  total_storage: total_storage,
87
113
  avg_storage: avg_storage,
88
114
  content_types: content_types,
89
- largest_blobs: []
115
+ largest_blobs: [],
116
+ generated_at: Time.current,
117
+ computing: false,
118
+ error: false
90
119
  }
91
120
  end
92
121
 
@@ -141,11 +170,7 @@ module LatoStorage
141
170
  end
142
171
 
143
172
  def deletable_blobs_count_loader
144
- count = 0
145
- ActiveStorage::Blob.left_joins(:attachments).where(active_storage_attachments: { blob_id: nil }).where('active_storage_blobs.created_at < ?', 12.hours.ago).find_each(batch_size: 1000) do |blob|
146
- count += 1
147
- end
148
- count
173
+ ActiveStorage::Blob.left_joins(:attachments).where(active_storage_attachments: { blob_id: nil }).where('active_storage_blobs.created_at < ?', 12.hours.ago).count
149
174
  rescue StandardError => e
150
175
  Rails.logger.error "Error estimating deletable blobs count: #{e.message}"
151
176
  Rails.logger.error e.backtrace.join("\n")
@@ -174,7 +199,7 @@ module LatoStorage
174
199
  end
175
200
 
176
201
  # Estimate content types by sampling blobs
177
- def content_types_loader
202
+ def content_types_loader(blobs_count)
178
203
  content_type_counts = Hash.new(0)
179
204
  sample_size = 5000
180
205
  sampled_count = 0
@@ -187,7 +212,7 @@ module LatoStorage
187
212
  return [] if sampled_count == 0
188
213
 
189
214
  # Scale counts to estimated total blobs count
190
- content_type_counts.transform_values! { |count| (count.to_f / sampled_count) * blobs_count_loader }
215
+ content_type_counts.transform_values! { |count| (count.to_f / sampled_count) * blobs_count }
191
216
  content_type_counts.sort_by { |_, count| -count }.first(5)
192
217
  rescue StandardError => e
193
218
  Rails.logger.error "Error estimating content types: #{e.message}"
@@ -6,13 +6,23 @@
6
6
  </div>
7
7
  <% end %>
8
8
 
9
+ <% if @data[:error] %>
10
+ <div class="alert alert-danger mb-3" role="alert"><%= I18n.t('lato_storage.computing_error') %></div>
11
+ <% elsif @data[:computing] %>
12
+ <div class="alert alert-warning mb-3" role="status"><%= I18n.t('lato_storage.computing') %></div>
13
+ <% end %>
14
+
15
+ <% if @data[:generated_at] %>
16
+ <p class="text-muted small"><%= I18n.t('lato_storage.generated_at', time: format_datetime(@data[:generated_at])) %></p>
17
+ <% end %>
18
+
9
19
  <div class="row">
10
20
  <div class="col col-6 col-lg-3 mb-3">
11
21
  <div class="card">
12
22
  <div class="card-body text-center">
13
23
  <div class="fw-bold fs-2"><%= @data[:blobs_count] %></div>
14
24
  <div><%= I18n.t('lato_storage.total_blobs') %></div>
15
- <%= link_to I18n.t('lato_storage.cta_see_all'), lato_storage.blobs_path, class: 'btn btn-primary btn-sm mt-3', data: { lato_action_target: 'trigger', turbo_frame: 'lato_index_default_active_storage_blob', action_size: 'xl', action_title: I18n.t('lato_storage.blobs') } %>
25
+ <%= link_to I18n.t('lato_storage.cta_see_all'), lato_storage.blobs_path, class: 'btn btn-primary btn-sm mt-3', aria: { label: I18n.t('lato_storage.see_all_aria', name: I18n.t('lato_storage.blobs')) }, data: { lato_action_target: 'trigger', turbo_frame: 'lato_index_default_active_storage_blob', action_size: 'xl', action_title: I18n.t('lato_storage.blobs') } %>
16
26
  </div>
17
27
  </div>
18
28
  </div>
@@ -22,7 +32,7 @@
22
32
  <div class="card-body text-center">
23
33
  <div class="fw-bold fs-2"><%= @data[:attachments_count] %></div>
24
34
  <div><%= I18n.t('lato_storage.total_attachments') %></div>
25
- <%= link_to I18n.t('lato_storage.cta_see_all'), lato_storage.attachments_path, class: 'btn btn-primary btn-sm mt-3', data: { lato_action_target: 'trigger', turbo_frame: 'lato_index_default_active_storage_attachment', action_size: 'xl', action_title: I18n.t('lato_storage.attachments') } %>
35
+ <%= link_to I18n.t('lato_storage.cta_see_all'), lato_storage.attachments_path, class: 'btn btn-primary btn-sm mt-3', aria: { label: I18n.t('lato_storage.see_all_aria', name: I18n.t('lato_storage.attachments')) }, data: { lato_action_target: 'trigger', turbo_frame: 'lato_index_default_active_storage_attachment', action_size: 'xl', action_title: I18n.t('lato_storage.attachments') } %>
26
36
  </div>
27
37
  </div>
28
38
  </div>
@@ -32,7 +42,7 @@
32
42
  <div class="card-body text-center">
33
43
  <div class="fw-bold fs-2"><%= @data[:variant_records_count] %></div>
34
44
  <div><%= I18n.t('lato_storage.total_variant_records') %></div>
35
- <%= link_to I18n.t('lato_storage.cta_see_all'), lato_storage.variant_records_path, class: 'btn btn-primary btn-sm mt-3', data: { lato_action_target: 'trigger', turbo_frame: 'lato_index_default_active_storage_variant_record', action_size: 'xl', action_title: I18n.t('lato_storage.variant_records') } %>
45
+ <%= link_to I18n.t('lato_storage.cta_see_all'), lato_storage.variant_records_path, class: 'btn btn-primary btn-sm mt-3', aria: { label: I18n.t('lato_storage.see_all_aria', name: I18n.t('lato_storage.variant_records')) }, data: { lato_action_target: 'trigger', turbo_frame: 'lato_index_default_active_storage_variant_record', action_size: 'xl', action_title: I18n.t('lato_storage.variant_records') } %>
36
46
  </div>
37
47
  </div>
38
48
  </div>
@@ -42,7 +52,7 @@
42
52
  <div class="card-body text-center">
43
53
  <div class="fw-bold fs-2"><%= @data[:deletable_blobs_count] %></div>
44
54
  <div><%= I18n.t('lato_storage.deletable_blobs') %></div>
45
- <%= link_to I18n.t('lato_storage.cta_free_space'), lato_storage.cleaner_path, class: 'btn btn-primary btn-sm mt-3', data: { turbo_method: :post, lato_action_target: 'trigger', turbo_frame: 'lato_operation' } %>
55
+ <%= link_to I18n.t('lato_storage.cta_free_space'), lato_storage.cleaner_path, class: 'btn btn-primary btn-sm mt-3', data: { turbo_method: :post, turbo_confirm: I18n.t('lato_storage.cleaner_confirm', count: @data[:deletable_blobs_count]), lato_action_target: 'trigger', turbo_frame: 'lato_operation' } %>
46
56
  </div>
47
57
  </div>
48
58
  </div>
@@ -67,12 +77,13 @@
67
77
  <div class="d-flex justify-content-between align-items-center">
68
78
  <strong><%= content_type %></strong>
69
79
  <span class="badge bg-primary rounded-pill">
70
- <%= count %> files
80
+ <%= I18n.t('lato_storage.files', count: count.round) %>
71
81
  </span>
72
82
  </div>
73
83
 
74
84
  <div class="progress mt-2">
75
- <div class="progress-bar" role="progressbar" style="width: <%= (count.to_f / total * 100).round(2) %>%" aria-valuenow="<%= count %>" aria-valuemin="0" aria-valuemax="<%= total %>"></div>
85
+ <% percentage = total.positive? ? (count.to_f / total * 100).round : 0 %>
86
+ <div class="progress-bar" role="progressbar" style="width: <%= percentage %>%" aria-label="<%= content_type %>" aria-valuenow="<%= percentage %>" aria-valuemin="0" aria-valuemax="100"></div>
76
87
  </div>
77
88
  </li>
78
89
  <% end %>
@@ -126,13 +137,14 @@
126
137
  <div class="list-group list-group-flush">
127
138
  <% @data[:largest_blobs].each do |blob| %>
128
139
  <a class="list-group-item list-group-item-action" href="<%= blob[:url] %>" target="_blank" rel="noopener noreferrer" download>
140
+ <span class="visually-hidden"><%= I18n.t('lato_storage.download_aria', filename: blob[:filename]) %> <%= I18n.t('lato_storage.new_tab') %></span>
129
141
  <div class="d-flex justify-content-between align-items-center">
130
142
  <strong class="text-truncate"><%= blob[:filename] %></strong>
131
143
  <div class="d-flex align-items-center ms-3">
132
144
  <span class="badge bg-primary rounded-pill">
133
145
  <%= format_bytes blob[:byte_size] %>
134
146
  </span>
135
- <i class="bi bi-download ms-2"></i>
147
+ <i class="bi bi-download ms-2" aria-hidden="true"></i>
136
148
  </div>
137
149
  </div>
138
150
  </a>
data/config/importmap.rb CHANGED
@@ -1,2 +1 @@
1
1
  pin "lato_storage/application", to: "lato_storage/application.js"
2
- pin_all_from LatoStorage::Engine.root.join("app/assets/javascripts/lato_storage/controllers"), under: "controllers", to: "lato_storage/controllers"
@@ -17,4 +17,19 @@ en:
17
17
  blobs: "Blobs"
18
18
  attachments: "Attachments"
19
19
  variant_records: "Variant Records"
20
- optimize_performances_active: "The displayed data is cached to optimize performance. The shown values are therefore not updated in real-time and calculated with an estimation method that may differ from the actual values."
20
+ optimize_performances_active: "The displayed data is cached to optimize performance. The shown values are therefore not updated in real-time and calculated with an estimation method that may differ from the actual values."
21
+ access_denied: "You have not access to this section."
22
+ variant_records_unavailable: "ActiveStorage::VariantRecord is not available in this version of Rails."
23
+ files:
24
+ one: "%{count} file"
25
+ other: "%{count} files"
26
+ new_tab: "(opens in a new tab)"
27
+ datetime_format: "%Y-%m-%d %H:%M:%S"
28
+ see_all_aria: "See all %{name}"
29
+ download_aria: "Download %{filename}"
30
+ cleaner_confirm: "Free up space? %{count} unattached blobs older than 12 hours will be permanently deleted from the database and from the storage service. This action cannot be undone."
31
+ cleaner_already_running: "A cleanup is already running. Wait a few minutes before starting another one."
32
+ cleaner_failed: "Unable to start the cleanup."
33
+ computing: "Statistics are being computed. Values shown are placeholders: reload this page in a few moments."
34
+ computing_error: "Unable to compute statistics. Check the application logs and try again later."
35
+ generated_at: "Updated at %{time}"
@@ -18,3 +18,18 @@ it:
18
18
  attachments: "Allegati"
19
19
  variant_records: "Varianti"
20
20
  optimize_performances_active: "I dati visualizzati sono cachati per ottimizzare le prestazioni. I valori mostrati non sono quindi aggiornati in tempo reale e calcolati con un metodo di stima che può differire dai valori effettivi."
21
+ access_denied: "Non hai accesso a questa sezione."
22
+ variant_records_unavailable: "ActiveStorage::VariantRecord non è disponibile in questa versione di Rails."
23
+ files:
24
+ one: "%{count} file"
25
+ other: "%{count} file"
26
+ new_tab: "(si apre in una nuova scheda)"
27
+ datetime_format: "%d/%m/%Y %H:%M:%S"
28
+ see_all_aria: "Vedi tutti: %{name}"
29
+ download_aria: "Scarica %{filename}"
30
+ cleaner_confirm: "Liberare spazio? %{count} blob non allegati da più di 12 ore saranno eliminati definitivamente dal database e dallo storage. L'operazione è irreversibile."
31
+ cleaner_already_running: "Una pulizia è già in corso. Attendi qualche minuto prima di avviarne un'altra."
32
+ cleaner_failed: "Impossibile avviare la pulizia."
33
+ computing: "Le statistiche sono in calcolo. I valori mostrati sono provvisori: ricarica la pagina tra qualche istante."
34
+ computing_error: "Impossibile calcolare le statistiche. Controlla i log dell'applicazione e riprova più tardi."
35
+ generated_at: "Aggiornato il %{time}"
@@ -11,8 +11,14 @@ module LatoStorage
11
11
  # Default is false.
12
12
  attr_accessor :optimize_performances
13
13
 
14
+ # Lifetime of the signed links to blobs shown in the panel.
15
+ # Links are generated on every page render (or cached with the dashboard data), so keep it short.
16
+ # Default is 12 hours.
17
+ attr_accessor :blob_url_expires_in
18
+
14
19
  def initialize
15
20
  @optimize_performances = false
21
+ @blob_url_expires_in = 12.hours
16
22
  end
17
23
  end
18
24
  end
@@ -1,3 +1,3 @@
1
1
  module LatoStorage
2
- VERSION = "3.1.3"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -1,11 +1,9 @@
1
- require 'fileutils'
2
-
3
1
  namespace :lato_storage do
4
2
  namespace :install do
5
- desc 'Install Lato storage engine and run tasks on main rails application'
3
+ desc 'No-op, kept for compatibility. Only lato_storage:install:migrations is required'
6
4
  # Usage: rails lato_storage:install:application
7
5
  task :application do
8
- # Free for future use...
6
+ # Nothing to install on the host application.
9
7
  end
10
8
  end
11
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante