activestorage-resumable 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eda37252cd9cae1c6209b5e2e788b82133748ae588cc3f2838be489a133f8171
4
- data.tar.gz: ae610ee86f19543e8aed92b95d046ab8021d62cdd27d6b68946f702aeb739ce6
3
+ metadata.gz: bb92b9f960cefc981ffb50b6bfce65e16cab57098074720359925dd270d18a18
4
+ data.tar.gz: 7612369a85184fae18a5ebc1ebc75723952d93efd76ee6f1a8d80b4d26029322
5
5
  SHA512:
6
- metadata.gz: 61c49a578d383213dd59ae28e0d06697ce25cc601e269613bcdf345fcdfa298311e3263c73e0b4747d56c055b0f65cc5658aca0abfe4ed8fc67534d2b96d1737
7
- data.tar.gz: e9be9cfa3dd80cda7e05b210213ff5e93cdd275be5aea86ff26e27de85a18a5930bc88c8c86fd8c98579f5ea28e2a083694ce6d9147af99c5698fca410ccfc58
6
+ metadata.gz: 2888771c2c559d58de0b983673a8c24c8962aca70871725fe39296cc50478e452a23a476abb8824a170f11243efa797ef59836beda743dda700083f11aa0a32e
7
+ data.tar.gz: 686b52a7baf55727554f0edb96e836cae17e6c2017e2f15f0c17684e17a04798fcec7ab52fc69610e7c7c99ee884b75c7b107875a44293722b8470fe3f5af257
data/README.md CHANGED
@@ -27,7 +27,15 @@ Active Storage Resumable, also includes a JavaScript library, that uploads file
27
27
  localStorage, allowing to resume an upload even after a browser restart.
28
28
 
29
29
  ### Resumable upload installation
30
- 1. Include `activestorage-resumable.js` in your application's JavaScript bundle.
30
+ 1. Export an environment variable called UPLOAD_ORIGIN_URL with the upload origin URL, for example
31
+ 'http://localhost:3000'. You can also create a `config/initializers/activestorage_resumable.rb` with the following:
32
+
33
+ ```ruby
34
+ ActiveStorage::Resumable.configure do |config|
35
+ config.upload_origin_url = 'https://mydomain.test:3000'
36
+ end
37
+ ```
38
+ 2. Include `activestorage-resumable.js` in your application's JavaScript bundle.
31
39
 
32
40
  Using the asset pipeline:
33
41
  ```js
@@ -37,12 +45,12 @@ localStorage, allowing to resume an upload even after a browser restart.
37
45
  ```js
38
46
  require("@fnix/activestorage-resumable").start()
39
47
  ```
40
- 2. Annotate file inputs with the resumable upload URL.
48
+ 3. Annotate file inputs with the resumable upload URL.
41
49
 
42
50
  ```ruby
43
51
  <%= form.file_field :attachments, multiple: true, resumable_upload: true %>
44
52
  ```
45
- 3. That's it! Uploads begin upon form submission.
53
+ 4. That's it! Uploads begin upon form submission.
46
54
 
47
55
  ### Resumable upload JavaScript events
48
56
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveStorage
4
4
  module Resumable
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.1'
6
6
  end
7
7
  end
@@ -2,18 +2,17 @@
2
2
 
3
3
  ActiveSupport.on_load(:active_storage_blob) do
4
4
  class ActiveStorage::Blob
5
- before_create do
6
- self.resumable_url = service.url_for_resumable_upload(key, content_type)
7
- end
8
-
9
5
  scope :resumable, -> { unattached.where.not(resumable_url: nil) }
10
6
  scope :active_resumable, -> { resumable.where('active_storage_blobs.created_at >= ?', 7.days.ago) }
11
7
  scope :expired_resumable, -> { resumable.where('active_storage_blobs.created_at < ?', 7.days.ago) }
12
8
 
13
9
  def self.find_or_create_before_resumable_upload!(filename:, byte_size:, checksum:, content_type: nil, metadata: nil)
14
- ActiveStorage::Blob.expired_resumable.destroy_all
15
- find_or_create_by! filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type,
16
- metadata: metadata
10
+ expired_resumable.destroy_all
11
+ active_resumable.find_or_create_by!(
12
+ filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type, metadata: metadata
13
+ ) do |blob|
14
+ blob.resumable_url = blob.service_url_for_resumable_upload
15
+ end
17
16
  end
18
17
 
19
18
  def uploaded_bytes
@@ -29,9 +28,8 @@ ActiveSupport.on_load(:active_storage_blob) do
29
28
  end
30
29
  end
31
30
 
32
- def service_url_for_resumable_upload(expires_in: ActiveStorage.service_urls_expire_in)
33
- service.url_for_resumable_upload key, expires_in: expires_in, content_type: content_type,
34
- content_length: byte_size, checksum: checksum
31
+ def service_url_for_resumable_upload
32
+ service.url_for_resumable_upload key, content_type: content_type
35
33
  end
36
34
  end
37
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage-resumable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kadu Diógenes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-01 00:00:00.000000000 Z
11
+ date: 2019-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activestorage