active_storage-archive 0.1.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/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +8 -0
- data/lib/active_storage/archive/version.rb +7 -0
- data/lib/active_storage/archive.rb +59 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0baea972dc061d129d7a8bea975a1ae53cadc1688a15921f0baa838ca5564d1e
|
|
4
|
+
data.tar.gz: abfd9196a6d74b93fae3273c9fe8e36f963b295b24057883984eaac71e9957c6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a6b31bcc1b0e74afe244cdfa87c516897766b36ba037628cb384f0805fd51a0481af19bc99122300a028235a2ce094e13dcc78fa78fed60afc711a85929baf76
|
|
7
|
+
data.tar.gz: 5fb2f8f456236914385164b901ff435f53a600ca4d8ca00be14d1e685bb5a5eab6e161918ecbcd4426824beb262b309b602b651c9d213c5941ffbfa30023fa91
|
data/.ruby-gemset
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
active_storage-archive
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-4.0.9
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Micah Geisel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "archive/version"
|
|
4
|
+
|
|
5
|
+
module ActiveStorage
|
|
6
|
+
module Archive
|
|
7
|
+
class ArchivedError < StandardError; end
|
|
8
|
+
|
|
9
|
+
mattr_accessor :tag, default: { "archived" => "true" } # object tag a bucket lifecycle rule moves to cold storage
|
|
10
|
+
mattr_accessor :fallback # ->(blob, disposition) { url } redirects to url; nil answers 410 Gone.
|
|
11
|
+
|
|
12
|
+
def self.configure = yield self
|
|
13
|
+
|
|
14
|
+
module BlobExtension
|
|
15
|
+
def archived? = metadata["archived_at"].present?
|
|
16
|
+
|
|
17
|
+
def archive!
|
|
18
|
+
with_lock do # so a stale copy can't clobber metadata
|
|
19
|
+
next if archived?
|
|
20
|
+
tag_for_archive if service.respond_to?(:bucket)
|
|
21
|
+
update_columns(metadata: metadata.merge("archived_at" => Time.current.iso8601))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
%i[url download download_chunk open].each do |reader|
|
|
26
|
+
define_method(reader) do |*args, **options, &block|
|
|
27
|
+
raise ArchivedError, "#{key} is archived" if archived?
|
|
28
|
+
super(*args, **options, &block)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def tag_for_archive
|
|
35
|
+
tag_set = Archive.tag.map { |name, value| { key: name, value: } }
|
|
36
|
+
service.client.client.put_object_tagging(bucket: service.bucket.name, key:, tagging: { tag_set: })
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module ControllerExtension
|
|
41
|
+
def show
|
|
42
|
+
if @blob.archived?
|
|
43
|
+
url = Archive.fallback&.call(@blob, params[:disposition])
|
|
44
|
+
url ? redirect_to(url, allow_other_host: true) : head(:gone)
|
|
45
|
+
else
|
|
46
|
+
super
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class Engine < ::Rails::Engine
|
|
52
|
+
config.to_prepare do
|
|
53
|
+
ActiveStorage::Blob.prepend(BlobExtension)
|
|
54
|
+
ActiveStorage::Blobs::RedirectController.prepend(ControllerExtension)
|
|
55
|
+
ActiveStorage::Blobs::ProxyController.prepend(ControllerExtension)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: active_storage-archive
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Micah Geisel
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: activestorage
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '8.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '8.1'
|
|
26
|
+
email:
|
|
27
|
+
- micah@botandrose.com
|
|
28
|
+
executables: []
|
|
29
|
+
extensions: []
|
|
30
|
+
extra_rdoc_files: []
|
|
31
|
+
files:
|
|
32
|
+
- ".ruby-gemset"
|
|
33
|
+
- ".ruby-version"
|
|
34
|
+
- LICENSE.txt
|
|
35
|
+
- Rakefile
|
|
36
|
+
- lib/active_storage/archive.rb
|
|
37
|
+
- lib/active_storage/archive/version.rb
|
|
38
|
+
homepage: https://github.com/botandrose/active_storage-archive
|
|
39
|
+
licenses:
|
|
40
|
+
- MIT
|
|
41
|
+
metadata:
|
|
42
|
+
homepage_uri: https://github.com/botandrose/active_storage-archive
|
|
43
|
+
source_code_uri: https://github.com/botandrose/active_storage-archive
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 3.3.0
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 4.0.20
|
|
59
|
+
specification_version: 4
|
|
60
|
+
summary: Archive Active Storage originals into cold storage after they age, and unarchive
|
|
61
|
+
them on demand.
|
|
62
|
+
test_files: []
|