activestorage-delayed 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +12 -5
- data/initializers/upload_default_variation.rb +2 -1
- data/lib/activestorage-delayed/delayed_uploader.rb +3 -2
- data/lib/activestorage-delayed/models/delayed_upload.rb +1 -1
- data/lib/activestorage-delayed/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76f19f1856294d83f52a92dbbc1ea9eb52c216c021726437ff513727426c65e4
|
4
|
+
data.tar.gz: 923f537ec4dbbfd797c72157f46b58a1a1f20f04127f53034f444fd6a2cd8ac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea37e642bef6ef9ba231b0bc0b2c8c1676b569679be5373bd45cd5f6cbd7f8aff4d1ac3642e1f6853fddf8e46f55f19293a38cf9fee4a60061b671c5cb27a3b0
|
7
|
+
data.tar.gz: 80d2123dec2953c7c8778e0f7fa9449e73b7f25625863e05f0edaf5c07e3c6782c3e4b44f824c14ab61bb3dc03a834ec94c6eebc340b298fb7061d11f02208fe
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
# Activestorage Delayed
|
2
2
|
|
3
|
-
ActiveStorage
|
4
|
-
This is a Ruby on Rails gem to upload activestorage files in background by saving them as base64 encoded in the database and be processed later.
|
3
|
+
ActiveStorage in Rails 6 and 7 does not support to upload files in background which in most cases delays the submit process and then makes the visitor get bored or receive a timeout error.
|
4
|
+
This is a Ruby on Rails gem to upload activestorage files in background by saving them as base64 encoded in the database (important for apps hosted in kubernetes) and be processed later.
|
5
|
+
|
6
|
+
## Features
|
7
|
+
- Upload files in background
|
8
|
+
- Ability to add new files instead of replacing the old ones when using using `has_many_attached`
|
9
|
+
- Ability to upload files with the original filename or a custom one
|
10
|
+
- Ability to preprocess the files before uploading them (Rails 7+)
|
11
|
+
Note: This gem assumes that the app has already configured activestorage.
|
5
12
|
|
6
13
|
## Installation
|
7
14
|
- Add this line to your application's Gemfile:
|
8
15
|
```ruby
|
9
|
-
gem 'activestorage-delayed'
|
16
|
+
gem 'activestorage-delayed', '>= 0.1.3'
|
10
17
|
```
|
11
18
|
- And then execute: `bundle install`
|
12
19
|
- Generate the migration: `rails g migration add_activestorage_delayed`
|
@@ -32,7 +39,7 @@ This is a Ruby on Rails gem to upload activestorage files in background by savin
|
|
32
39
|
class User < ApplicationRecord
|
33
40
|
include ActivestorageDelayed::DelayedConcern
|
34
41
|
|
35
|
-
has_one_attached :photo,
|
42
|
+
has_one_attached :photo, required: true, use_filename: true
|
36
43
|
delayed_attach :photo
|
37
44
|
|
38
45
|
has_many_attached :certificates
|
@@ -41,7 +48,7 @@ end
|
|
41
48
|
|
42
49
|
```
|
43
50
|
### `delayed_attach` accepts an optional hash with the following options:
|
44
|
-
- `
|
51
|
+
- `required`: If set to `true`, the `photo` or the `photo_tmp` will be required before saving.
|
45
52
|
- `use_filename`: If set to `true`, the image filename will be used as the name of uploaded file instead of the hash-key used by `activestorage`
|
46
53
|
|
47
54
|
### Examples to upload files in background
|
@@ -6,12 +6,13 @@ module ActivetoragePreprocessDefaultVariation
|
|
6
6
|
base.extend(ClassMethods)
|
7
7
|
end
|
8
8
|
|
9
|
-
def upload_without_unfurling(io)
|
9
|
+
def upload_without_unfurling(io) # rubocop:disable Metrics/MethodLength
|
10
10
|
variant = attachments.first.try(:send, :variants)
|
11
11
|
default_variant = variant ? variant[:default] : nil
|
12
12
|
if default_variant && self.class.enabled_default_variant?
|
13
13
|
ActiveStorage::Variation.wrap(default_variant).transform(io) do |output|
|
14
14
|
unfurl output, identify: identify
|
15
|
+
save! if id.present? # update new unfurl information
|
15
16
|
super(output)
|
16
17
|
end
|
17
18
|
else
|
@@ -13,8 +13,7 @@ module ActivestorageDelayed
|
|
13
13
|
return unless delayed_upload
|
14
14
|
|
15
15
|
remove_files
|
16
|
-
upload_photos
|
17
|
-
save_changes
|
16
|
+
save_changes if upload_photos
|
18
17
|
end
|
19
18
|
|
20
19
|
private
|
@@ -25,9 +24,11 @@ module ActivestorageDelayed
|
|
25
24
|
tmp_files_data.each do |file_data|
|
26
25
|
model.send(attr_name).attach(file_data.transform_keys(&:to_sym))
|
27
26
|
end
|
27
|
+
true
|
28
28
|
rescue => e # rubocop:disable Style/RescueStandardError
|
29
29
|
Rails.logger.error("********* #{self.class.name} -> Failed uploading files: #{e.message}. #{e.backtrace[0..20]}")
|
30
30
|
model.ast_delayed_on_error(attr_name, e)
|
31
|
+
false
|
31
32
|
end
|
32
33
|
|
33
34
|
def save_changes
|
@@ -10,7 +10,7 @@ module ActivestorageDelayed
|
|
10
10
|
self.table_name = 'activestorage_delayed_uploads'
|
11
11
|
attr_accessor :tmp_files
|
12
12
|
|
13
|
-
belongs_to :uploadable, polymorphic: true
|
13
|
+
belongs_to :uploadable, polymorphic: true, touch: true
|
14
14
|
|
15
15
|
before_save :parse_tmp_files
|
16
16
|
after_create_commit do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activestorage-delayed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Owen Peredo Diaz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04
|
11
|
+
date: 2022-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activestorage
|