active_storage_dashboard 0.1.6 → 0.1.8

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: 37a9ff508b9a3249ca7bda98dbfca0f7aa2629e35168958b0eca00d82d2cd27f
4
- data.tar.gz: 6eac31451e7615696babb0f89de47d31f881d6ab392d9600907ed26b5733574e
3
+ metadata.gz: 52688deaa501817d673f48ffe6844b5eacf8907e7772a8947685af641e7f44df
4
+ data.tar.gz: 6bb6a6aba5a21ba5bf4ab7d66c54b9803a3523ed37c3d7274917698d107dc6aa
5
5
  SHA512:
6
- metadata.gz: 86378de269473f43fdc742d95f2dce3197f22ddc4726a5e9e91f56ae4a77a05df3fa2094ac0789d20734edbc99235050db81ffecddce74117422113ab43f13df
7
- data.tar.gz: 466081bfa71b093cfbed38febfb5810a020cf8a40922f6098e41848a0a90a0bc6d6968302a0b381dc8b163851f6034a5bf0bf13a39c43b54dda64bd296c78ee7
6
+ metadata.gz: e109061b41d12ecfa053d87e2e0a1a5b90083e27a04a9d8dcc40702909d414cd027d6bbc61681c407c5d0e2fac4c107505722058d97a51aa139cad6f0e4a7f38
7
+ data.tar.gz: b9ad63bb467d849d9591c3f539bd96aaa3706b8d84ae037162f33bed921a2e75978624bb960179ff0a95298b32dede9eb0265b006e56431be41dc3dba9bfa017
data/README.md CHANGED
@@ -46,20 +46,41 @@ Then visit `/active-storage-dashboard` in your browser to see the beautiful dash
46
46
 
47
47
  The dashboard provides direct file download capabilities from both the list and detail views. Simply click on the download button to get your files.
48
48
 
49
+ ### Tasks
50
+
51
+ The dashboard includes a task to remove unused blobs and attachments.
52
+
53
+ You can run this task from the command line:
54
+
55
+ ```bash
56
+ $ rails active_storage:dashboard:purge_orphans
57
+ ```
58
+ Re-analyze blobs that are not yet analyzed
59
+ ```bash
60
+ $ rails active_storage:dashboard:reanalyze
61
+ ```
62
+
63
+ Regenerate missing or outdated variants
64
+ ```bash
65
+ $ rails active_storage:dashboard:regenerate_variants
66
+ ```
67
+
68
+
69
+
49
70
  ### 📸 Screenshots
50
71
 
51
72
  <details>
52
73
  <summary>Click to see more screenshots</summary>
53
-
74
+
54
75
  #### Dashboard Overview
55
76
  ![Dashboard Overview](https://github.com/giovapanasiti/active_storage_dashboard/blob/main/screenshots/dashboard.png)
56
-
77
+
57
78
  #### Blob Details
58
79
  ![Blob Details](https://github.com/giovapanasiti/active_storage_dashboard/blob/main/screenshots/blob-details.png)
59
-
80
+
60
81
  #### Files Gallery
61
82
  ![Files Gallery](https://github.com/giovapanasiti/active_storage_dashboard/blob/main/screenshots/files-gallery.png)
62
-
83
+
63
84
  </details>
64
85
 
65
86
  ## 🔒 Security Considerations
@@ -81,6 +102,11 @@ constraints lambda { |req| req.session[:user_id].present? || (req.env['warden']
81
102
  end
82
103
  ```
83
104
 
105
+ Or, in your environment config or `application.rb`:
106
+ ```ruby
107
+ config.active_storage_dashboard.base_controller_class = "AdminController"
108
+ ```
109
+
84
110
 
85
111
  ## 🤝 Contributing
86
112
 
@@ -88,4 +114,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/giovap
88
114
 
89
115
  ## 📝 License
90
116
 
91
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
117
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveStorageDashboard
4
- class ApplicationController < ActionController::Base
4
+ class ApplicationController < ActiveStorageDashboard.base_controller_class.constantize
5
5
  protect_from_forgery with: :exception
6
-
6
+
7
7
  # Simple pagination without external dependencies
8
8
  helper_method :paginate
9
9
 
@@ -12,4 +12,4 @@ module ActiveStorageDashboard
12
12
  scope.limit(per_page).offset((@page - 1) * per_page)
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -0,0 +1,9 @@
1
+ module ActiveStorageDashboard
2
+ class Analyzer
3
+ def self.call
4
+ ActiveStorage::Blob.find_each do |blob|
5
+ blob.analyze unless blob.analyzed?
6
+ end
7
+ end
8
+ end
9
+ end
@@ -3,10 +3,18 @@
3
3
  module ActiveStorageDashboard
4
4
  class Engine < ::Rails::Engine
5
5
  isolate_namespace ActiveStorageDashboard
6
-
6
+
7
7
  # Ensure URLs are generated correctly by setting defaults
8
8
  initializer "active_storage_dashboard.url_options" do |app|
9
9
  ActiveStorageDashboard::Engine.routes.default_url_options = app.routes.default_url_options
10
10
  end
11
+
12
+ config.active_storage_dashboard = ActiveSupport::OrderedOptions.new
13
+
14
+ config.before_initialize do
15
+ config.active_storage_dashboard.each do |key, value|
16
+ ActiveStorageDashboard.public_send("#{key}=", value)
17
+ end
18
+ end
11
19
  end
12
- end
20
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveStorageDashboard
2
+ class OrphanPurger
3
+ def self.call
4
+ scope = ActiveStorage::Blob.left_outer_joins(:attachments)
5
+ .where(active_storage_attachments: { id: nil })
6
+
7
+ scope.find_each do |blob|
8
+ blob.purge
9
+ puts "Purged blob #{blob.id}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module ActiveStorageDashboard
2
+ class VariantRegenerator
3
+ def self.call
4
+ unless defined?(ActiveStorage::VariantRecord)
5
+ puts "ActiveStorage::VariantRecord not found (Rails < 7.1). Skipping."
6
+ return
7
+ end
8
+
9
+ ActiveStorage::VariantRecord.find_each do |variant|
10
+ begin
11
+ variant.image.representation(variant.variation).processed
12
+ rescue => e
13
+ warn "Failed variant #{variant.id}: #{e.message}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,8 +1,19 @@
1
1
  # frozen_string_literal: true
2
+ require "rails/railtie"
2
3
 
3
4
  require "active_storage_dashboard/version"
4
5
  require "active_storage_dashboard/engine"
5
6
 
7
+ require "active_storage_dashboard/orphan_purger"
8
+ require "active_storage_dashboard/analyzer"
9
+ require "active_storage_dashboard/variant_regenerator"
10
+
6
11
  module ActiveStorageDashboard
7
- # Your code goes here...
8
- end
12
+ mattr_accessor :base_controller_class, default: "ActionController::Base"
13
+
14
+ class Railtie < Rails::Railtie
15
+ rake_tasks do
16
+ load File.expand_path("tasks/active_storage_dashboard_tasks.rake", __dir__)
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,21 @@
1
- # frozen_string_literal: true
1
+ namespace :active_storage do
2
+ namespace :dashboard do
3
+ desc "Purge blobs that have no attachments"
4
+ task purge_orphans: :environment do
5
+ ActiveStorageDashboard::OrphanPurger.call
6
+ end
2
7
 
3
- # desc "Explaining what the task does"
4
- # task :active_storage_dashboard do
5
- # # Task goes here
6
- # end
8
+ desc "Re-analyze blobs that are not yet analyzed"
9
+ task reanalyze: :environment do
10
+ ActiveStorageDashboard::Analyzer.call
11
+ end
12
+
13
+ desc "Recreate missing or outdated variants"
14
+ task regenerate_variants: :environment do
15
+ ActiveStorageDashboard::VariantRegenerator.call
16
+ end
17
+
18
+ desc "Run all maintenance tasks"
19
+ task all: [:purge_orphans, :reanalyze, :regenerate_variants]
20
+ end
21
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_storage_dashboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Panasiti
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-17 00:00:00.000000000 Z
10
+ date: 2025-06-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -49,7 +49,10 @@ files:
49
49
  - app/views/layouts/active_storage_dashboard/application.html.erb
50
50
  - config/routes.rb
51
51
  - lib/active_storage_dashboard.rb
52
+ - lib/active_storage_dashboard/analyzer.rb
52
53
  - lib/active_storage_dashboard/engine.rb
54
+ - lib/active_storage_dashboard/orphan_purger.rb
55
+ - lib/active_storage_dashboard/variant_regenerator.rb
53
56
  - lib/active_storage_dashboard/version.rb
54
57
  - lib/tasks/active_storage_dashboard_tasks.rake
55
58
  homepage: https://github.com/giovapanasiti/active_storage_dashboard