lato_storage 3.0.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +71 -0
- data/Rakefile +8 -0
- data/app/assets/config/lato_storage_manifest.js +2 -0
- data/app/assets/javascripts/lato_storage/application.js +1 -0
- data/app/assets/stylesheets/lato_storage/application.scss +0 -0
- data/app/controllers/lato_storage/application_controller.rb +30 -0
- data/app/helpers/lato_storage/application_helper.rb +16 -0
- data/app/jobs/lato_storage/application_job.rb +4 -0
- data/app/mailers/lato_storage/application_mailer.rb +6 -0
- data/app/views/lato_storage/application/index.html.erb +134 -0
- data/config/importmap.rb +2 -0
- data/config/locales/en.yml +14 -0
- data/config/locales/it.yml +14 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20250328072343_add_lato_storage_admin_to_lato_user.rb +5 -0
- data/lib/lato_storage/config.rb +10 -0
- data/lib/lato_storage/engine.rb +13 -0
- data/lib/lato_storage/version.rb +3 -0
- data/lib/lato_storage.rb +15 -0
- data/lib/tasks/lato_storage_tasks.rake +11 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1d05661b7389e2ddbde1a533b1da8175cfb487df74268efaae8d36aedddfb8b7
|
4
|
+
data.tar.gz: e9d0f31b63fafc2d37553733a3170cccce4c7a9d694d2e29a7f37497d7a55417
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7994b4bab09fba75f5868af1d5a71bbe6c62604438a2d96dfee8b92fab54baf2478e043e7ed79f46d2697d39f3fcccdc91c5dd7e539ea0467eb7326457b28f59
|
7
|
+
data.tar.gz: a60279cc560d60620ddd78bdf7752d8a8ded7684714e4c073e7e5a69caa14b9341ffc2d01310103319ee5d3b92cfc2d6db9337c2f56b5eca19037473917fe8fc
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright Gregorio Galante
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Lato Storage
|
2
|
+
Manage application storage (ActiveStorage data) on Lato projects.
|
3
|
+
|
4
|
+
🚨 THIS GEM IN UNDER DEVELOPMENT 🚨
|
5
|
+
|
6
|
+
NOTE: This gem is using [Active Storage Dashboard](https://github.com/giovapanasiti/active_storage_dashboard) as reference for the interface and the functionality. The idea is to provide a similar interface inside Lato.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
Add required dependencies to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# Use lato as application panel
|
13
|
+
gem "lato"
|
14
|
+
gem "lato_storage"
|
15
|
+
```
|
16
|
+
|
17
|
+
Install gem and run required tasks:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
$ bundle
|
21
|
+
$ rails lato_storage:install:application
|
22
|
+
$ rails lato_storage:install:migrations
|
23
|
+
$ rails db:migrate
|
24
|
+
```
|
25
|
+
|
26
|
+
Mount lato storage routes on the **config/routes.rb** file:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Rails.application.routes.draw do
|
30
|
+
mount LatoStorage::Engine => "/lato-storage"
|
31
|
+
|
32
|
+
# ....
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
Import Lato Scss on **app/assets/stylesheets/application.scss** file:
|
37
|
+
```scss
|
38
|
+
@import 'lato_storage/application';
|
39
|
+
|
40
|
+
// ....
|
41
|
+
```
|
42
|
+
|
43
|
+
Import Lato Storage Js on **app/javascript/application.js** file:
|
44
|
+
```js
|
45
|
+
import "lato_storage/application";
|
46
|
+
|
47
|
+
// ....
|
48
|
+
```
|
49
|
+
|
50
|
+
## Development
|
51
|
+
|
52
|
+
Clone repository, install dependencies, run migrations and start:
|
53
|
+
|
54
|
+
```shell
|
55
|
+
$ git clone https://github.com/Lato-GAM/lato_storage
|
56
|
+
$ cd lato_storage
|
57
|
+
$ bundle
|
58
|
+
$ rails db:migrate
|
59
|
+
$ rails db:seed
|
60
|
+
$ foreman start -f Procfile.dev
|
61
|
+
```
|
62
|
+
|
63
|
+
## Publish
|
64
|
+
|
65
|
+
```shell
|
66
|
+
$ ruby ./bin/publish.rb
|
67
|
+
```
|
68
|
+
|
69
|
+
## License
|
70
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
71
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
console.log("Lato Settings JS loaded");
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module LatoStorage
|
2
|
+
class ApplicationController < Lato::ApplicationController
|
3
|
+
layout 'lato/application'
|
4
|
+
before_action :authenticate_session
|
5
|
+
before_action :authenticate_lato_storage_admin
|
6
|
+
before_action { active_sidebar(:lato_storage); active_navbar(:lato_storage) }
|
7
|
+
|
8
|
+
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
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def authenticate_lato_storage_admin
|
25
|
+
return true if @session.user&.lato_storage_admin
|
26
|
+
|
27
|
+
redirect_to lato.root_path, alert: 'You have not access to this section.'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module LatoStorage
|
2
|
+
module ApplicationHelper
|
3
|
+
|
4
|
+
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]}"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
<%= lato_page_head I18n.t('lato_storage.storage') %>
|
2
|
+
|
3
|
+
<div class="row">
|
4
|
+
<div class="col col-6 col-lg-3 mb-3">
|
5
|
+
<div class="card">
|
6
|
+
<div class="card-body text-center">
|
7
|
+
<div class="fw-bold fs-2"><%= @blobs_count %></div>
|
8
|
+
<div><%= I18n.t('lato_storage.total_blobs') %></div>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div class="col col-6 col-lg-3 mb-3">
|
14
|
+
<div class="card">
|
15
|
+
<div class="card-body text-center">
|
16
|
+
<div class="fw-bold fs-2"><%= @attachments_count %></div>
|
17
|
+
<div><%= I18n.t('lato_storage.total_attachments') %></div>
|
18
|
+
</div>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div class="col col-6 col-lg-3 mb-3">
|
23
|
+
<div class="card">
|
24
|
+
<div class="card-body text-center">
|
25
|
+
<div class="fw-bold fs-2"><%= @variant_records_count %></div>
|
26
|
+
<div><%= I18n.t('lato_storage.total_variant_records') %></div>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<div class="col col-6 col-lg-3 mb-3">
|
32
|
+
<div class="card">
|
33
|
+
<div class="card-body text-center">
|
34
|
+
<div class="fw-bold fs-2"><%= @deletable_blobs_count %></div>
|
35
|
+
<div><%= I18n.t('lato_storage.deletable_blobs') %></div>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
</div>
|
39
|
+
|
40
|
+
<div class="col col-12 col-lg-6 mb-3">
|
41
|
+
<div class="card">
|
42
|
+
<div class="card-header">
|
43
|
+
<h5 class="card-title mb-0">
|
44
|
+
<%= I18n.t('lato_storage.content_type_distribution') %>
|
45
|
+
</h5>
|
46
|
+
</div>
|
47
|
+
<div class="card-body">
|
48
|
+
<% if @content_types.any? %>
|
49
|
+
<% total = @content_types.sum { |_, count| count } %>
|
50
|
+
<ul class="list-group list-group-flush">
|
51
|
+
<% @content_types.each do |content_type, count| %>
|
52
|
+
<li class="list-group-item">
|
53
|
+
<div class="d-flex justify-content-between align-items-center">
|
54
|
+
<strong><%= content_type %></strong>
|
55
|
+
<span class="badge bg-primary rounded-pill">
|
56
|
+
<%= count %> files
|
57
|
+
</span>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div class="progress mt-2">
|
61
|
+
<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>
|
62
|
+
</div>
|
63
|
+
</li>
|
64
|
+
<% end %>
|
65
|
+
</ul>
|
66
|
+
<% else %>
|
67
|
+
<div class="alert alert-info mb-0">
|
68
|
+
<%= I18n.t('lato_storage.no_content_types') %>
|
69
|
+
</div>
|
70
|
+
<% end %>
|
71
|
+
</div>
|
72
|
+
</div>
|
73
|
+
</div>
|
74
|
+
|
75
|
+
<div class="col col-12 col-lg-6 mb-3">
|
76
|
+
<div class="card mb-3">
|
77
|
+
<div class="card-header">
|
78
|
+
<h5 class="card-title mb-0">
|
79
|
+
<%= I18n.t('lato_storage.storage_usage') %>
|
80
|
+
</h5>
|
81
|
+
</div>
|
82
|
+
<div class="card-body row">
|
83
|
+
<div class="col col-12 col-md-6 mb-3 mb-md-0">
|
84
|
+
<div class="card">
|
85
|
+
<div class="card-body text-center">
|
86
|
+
<div class="fw-bold fs-2"><%= format_bytes @total_storage %></div>
|
87
|
+
<div><%= I18n.t('lato_storage.total_storage') %></div>
|
88
|
+
</div>
|
89
|
+
</div>
|
90
|
+
</div>
|
91
|
+
|
92
|
+
<div class="col col-12 col-md-6 mb-3 mb-md-0">
|
93
|
+
<div class="card">
|
94
|
+
<div class="card-body text-center">
|
95
|
+
<div class="fw-bold fs-2"><%= format_bytes @avg_storage %></div>
|
96
|
+
<div><%= I18n.t('lato_storage.avg_storage') %></div>
|
97
|
+
</div>
|
98
|
+
</div>
|
99
|
+
</div>
|
100
|
+
</div>
|
101
|
+
</div>
|
102
|
+
|
103
|
+
<div class="card">
|
104
|
+
<div class="card-header">
|
105
|
+
<h5 class="card-title mb-0">
|
106
|
+
<%= I18n.t('lato_storage.largest_blobs') %>
|
107
|
+
</h5>
|
108
|
+
</div>
|
109
|
+
<div class="card-body">
|
110
|
+
<% if @largest_blobs.any? %>
|
111
|
+
<div class="list-group list-group-flush">
|
112
|
+
<% @largest_blobs.each do |blob| %>
|
113
|
+
<a class="list-group-item list-group-item-action" href="<%= main_app.url_for(blob) %>" target="_blank" rel="noopener noreferrer" download>
|
114
|
+
<div class="d-flex justify-content-between align-items-center">
|
115
|
+
<strong><%= blob.filename %></strong>
|
116
|
+
<div class="d-flex align-items-center">
|
117
|
+
<span class="badge bg-primary rounded-pill">
|
118
|
+
<%= format_bytes blob.byte_size %>
|
119
|
+
</span>
|
120
|
+
<i class="bi bi-download ms-2"></i>
|
121
|
+
</div>
|
122
|
+
</div>
|
123
|
+
</a>
|
124
|
+
<% end %>
|
125
|
+
</div>
|
126
|
+
<% else %>
|
127
|
+
<div class="alert alert-info mb-0">
|
128
|
+
<%= I18n.t('lato_storage.no_largest_blobs') %>
|
129
|
+
</div>
|
130
|
+
<% end %>
|
131
|
+
</div>
|
132
|
+
</div>
|
133
|
+
</div>
|
134
|
+
</div>
|
data/config/importmap.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
en:
|
2
|
+
lato_storage:
|
3
|
+
storage: "Storage"
|
4
|
+
total_blobs: "Total Blobs"
|
5
|
+
total_attachments: "Total Attachments"
|
6
|
+
total_variant_records: "Total Variant Records"
|
7
|
+
total_storage: "Total Storage"
|
8
|
+
avg_storage: "Storage per Blob"
|
9
|
+
content_type_distribution: "Content Type Distribution"
|
10
|
+
no_content_types: "No Content Types available"
|
11
|
+
storage_usage: "Storage Usage"
|
12
|
+
largest_blobs: "Largest Blobs"
|
13
|
+
no_largest_blobs: "No Blobs available"
|
14
|
+
deletable_blobs: "Deletable Blobs"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
it:
|
2
|
+
lato_storage:
|
3
|
+
storage: "Storage"
|
4
|
+
total_blobs: "Blob totali"
|
5
|
+
total_attachments: "Allegati totali"
|
6
|
+
total_variant_records: "Varianti totali"
|
7
|
+
total_storage: "Storage totale"
|
8
|
+
avg_storage: "Storage per Blob"
|
9
|
+
content_type_distribution: "Distribuzione dei contenuti"
|
10
|
+
no_content_types: "Nessun tipo di contenuto disponibile"
|
11
|
+
storage_usage: "Utilizzo dello storage"
|
12
|
+
largest_blobs: "Blob più grandi"
|
13
|
+
no_largest_blobs: "Nessun blob disponibile"
|
14
|
+
deletable_blobs: "Blob eliminabili"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module LatoStorage
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace LatoStorage
|
4
|
+
|
5
|
+
initializer 'lato_storage.importmap', before: 'importmap' do |app|
|
6
|
+
app.config.importmap.paths << root.join('config/importmap.rb')
|
7
|
+
end
|
8
|
+
|
9
|
+
initializer "lato_storage.precompile" do |app|
|
10
|
+
app.config.assets.precompile << "lato_storage_manifest.js"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/lato_storage.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
namespace :lato_storage do
|
4
|
+
namespace :install do
|
5
|
+
desc 'Install Lato storage engine and run tasks on main rails application'
|
6
|
+
# Usage: rails lato_storage:install:application
|
7
|
+
task :application do
|
8
|
+
# Free for future use...
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lato_storage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregorio Galante
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: lato
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A Rails engine to manage application storage on Lato projects!
|
42
|
+
email:
|
43
|
+
- me@gregoriogalante.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- MIT-LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- app/assets/config/lato_storage_manifest.js
|
52
|
+
- app/assets/javascripts/lato_storage/application.js
|
53
|
+
- app/assets/stylesheets/lato_storage/application.scss
|
54
|
+
- app/controllers/lato_storage/application_controller.rb
|
55
|
+
- app/helpers/lato_storage/application_helper.rb
|
56
|
+
- app/jobs/lato_storage/application_job.rb
|
57
|
+
- app/mailers/lato_storage/application_mailer.rb
|
58
|
+
- app/views/lato_storage/application/index.html.erb
|
59
|
+
- config/importmap.rb
|
60
|
+
- config/locales/en.yml
|
61
|
+
- config/locales/it.yml
|
62
|
+
- config/routes.rb
|
63
|
+
- db/migrate/20250328072343_add_lato_storage_admin_to_lato_user.rb
|
64
|
+
- lib/lato_storage.rb
|
65
|
+
- lib/lato_storage/config.rb
|
66
|
+
- lib/lato_storage/engine.rb
|
67
|
+
- lib/lato_storage/version.rb
|
68
|
+
- lib/tasks/lato_storage_tasks.rake
|
69
|
+
homepage: https://github.com/Lato-org/lato_storage
|
70
|
+
licenses:
|
71
|
+
- MIT
|
72
|
+
metadata:
|
73
|
+
homepage_uri: https://github.com/Lato-org/lato_storage
|
74
|
+
source_code_uri: https://github.com/Lato-org/lato_storage
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.4.1
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Another engine for Lato projects
|
94
|
+
test_files: []
|