simple_active_storage 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 955a5b4ce800ff9cba383eeb001c4ce7d45e1858
4
- data.tar.gz: 8af2618a3421db7915fa9908e0de88e48995d18b
3
+ metadata.gz: 642cee73e9cefa777da14f34728f9f73cd5f814d
4
+ data.tar.gz: a1816cac9a5dabc1c7862be75edc68ef74a16ada
5
5
  SHA512:
6
- metadata.gz: 7a5f9d4f2e558672f6e9a12a827e61fd2dfd95de02b1374e9ba3ad7e1db276a7bfabd5a891f1a602da3a83240ccf4f41aa3ee2ea2ef28500abee3deae5009b21
7
- data.tar.gz: 269d65805eee43153d494610dd925211281417928e3efdeecb144706604536d18bdfb583d2355d19dbab75110200a713ce16c85e363591f55fbf969371510795
6
+ metadata.gz: b435641a3ba3b8ef53719e1614fc60d451c93ba012e12930657d1a99c61cbc3c5367639e187f5b5d5f71626ee10a6b6832e5524e4e51fef76e0e5f4f5768ce57
7
+ data.tar.gz: 1157fef26391f004346806924ce76c28a865856a43fb8bb10c0f7f217181667ed9678b27f56d1bcd0ce6ce0eb76e15b7aeec9985345366975f2bfb6288b76d9f
data/README.md CHANGED
@@ -1,22 +1,24 @@
1
1
  # SimpleActiveStorage
2
- 发现ActiveStorage在模型里面获取url非常不方便,想写一个容易的
3
- 比如
2
+ *first of all,I need to apologize for my pool english.*
3
+
4
+ when you using active storage
5
+ there are some inconvenient things, such as you get the url of attachment:
4
6
  ```ruby
5
- user.avatar.variant("100x100")
7
+ user.avatar.variant(resize: "100x100")
6
8
  ```
7
- 每次都要写100x100多不方便
8
- 我们是不是可以这样写
9
+
10
+ you need repeat `resize: "100x100"` every time.
11
+
12
+
13
+ I need a short cut to replace `resize: "100x100"`, like this:
14
+
9
15
  ```ruby
10
16
  user.avatar.variant(:thumb)
11
- ```
12
- 这样是不是更简单一些
13
- url也很不方便,每次都需要url_for才能获取到
14
- 我们是不是能
15
- ```ruby
16
17
  user.avatar.path
17
18
  user.avatar.url
18
19
  ```
19
- 这样更简单一点呢
20
+
21
+ SimpleActiveStorage is do such thing.
20
22
 
21
23
  ## Usage
22
24
 
@@ -58,6 +60,40 @@ photo.url # => "http://www.example.com/rails/active_storage/blob
58
60
  photo.blob.url # => "http://www.example.com/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCdz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--e81a87b1d919f371e6b665e2c01301cff6d16a26/test.png"
59
61
  ```
60
62
 
63
+
64
+ ### direct upload
65
+ when use activestorage direct upload
66
+ activestorage.js will make an ajax post to /rails/active_storage/direct_uploads
67
+ and return json data it looks like below:
68
+
69
+ ```javascript
70
+ {
71
+ "id": 4,
72
+ "key": "veeUd2b2toSbym6DmZ2pLkoZ",
73
+ "filename": "avatar.jpg",
74
+ "content_type": "image/jpeg",
75
+ "metadata": {},
76
+ "byte_size": 145516,
77
+ "checksum": "/uNyp1jXJPXLBD6X0XZn7g==",
78
+ "created_at": "2018-05-29T16:50:51.801Z",
79
+ "signed_id": "eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--578572a7c2d5925ac32622a7d7b832f68c536f51",
80
+ "direct_upload": {
81
+ "url": "http://localhost:3001/rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdDVG9JYTJWNVNTSWRkbVZsVldReVlqSjBiMU5pZVcwMlJHMWFNbkJNYTI5YUJqb0dSVlE2RVdOdmJuUmxiblJmZEhsd1pVa2lEMmx0WVdkbEwycHdaV2NHT3daVU9oTmpiMjUwWlc1MFgyeGxibWQwYUdrRGJEZ0NPZzFqYUdWamEzTjFiVWtpSFM5MVRubHdNV3BZU2xCWVRFSkVObGd3V0ZwdU4yYzlQUVk3QmxRPSIsImV4cCI6IjIwMTgtMDUtMjlUMTY6NTU6NTIuMTgxWiIsInB1ciI6ImJsb2JfdG9rZW4ifX0=--b2deb5a21ef8b7a2a08cf354052a65e640be6450",
82
+ "headers": {
83
+ "Content-Type": "image/jpeg"
84
+ }
85
+ },
86
+ "transformations": {
87
+ "thumb": "http://www.example.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--578572a7c2d5925ac32622a7d7b832f68c536f51/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld1k2QzNKbGMybDZaVWtpRERFd01IZ3hNREFHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--20ae94033d7a10dcb862bd24c1dcbb3740e61e7c/avatar.jpg",
88
+ "tiny": "http://www.example.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--578572a7c2d5925ac32622a7d7b832f68c536f51/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld1k2QzNKbGMybDZaVWtpQ2pJd2VESXdCam9HUlZRPSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--c8fb6fe35e8d91c55a9323e9858130607ecdb1bf/avatar.jpg",
89
+ "medium": "http://www.example.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBDUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--578572a7c2d5925ac32622a7d7b832f68c536f51/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VWTI5dFltbHVaVjl2Y0hScGIyNXpld1k2QzNKbGMybDZaVWtpRERRd01IZzBNREFHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--b87eb27c4abc3f9bd937642f2e5809bfd553edf8/avatar.jpg"
90
+ }
91
+ }
92
+ ```
93
+
94
+ originally there is no transformations field in json data.
95
+ the transformations field data is provide by SimpleActiveStorage.
96
+
61
97
  ## Installation
62
98
  Add this line to your application's Gemfile:
63
99
 
@@ -0,0 +1,16 @@
1
+ module SimpleActiveStorage
2
+ module DirectUploadsController
3
+ extend ActiveSupport::Concern
4
+ private
5
+ def direct_upload_json(blob)
6
+ data = super(blob)
7
+ # add additional data
8
+ transformations = {}
9
+ SimpleActiveStorage.transformations.keys.each do |key|
10
+ transformations[key] = blob.variant(key).url
11
+ end
12
+ data[:transformations] = transformations
13
+ data
14
+ end
15
+ end
16
+ end
@@ -12,6 +12,10 @@ module SimpleActiveStorage
12
12
 
13
13
  end
14
14
 
15
+ config.after_initialize do
16
+ ActiveStorage::DirectUploadsController.send :prepend,SimpleActiveStorage::DirectUploadsController
17
+ end
18
+
15
19
  end
16
20
 
17
21
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleActiveStorage
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "simple_active_storage/railtie"
2
2
  require "simple_active_storage/variation"
3
3
  require "simple_active_storage/url"
4
+ require "simple_active_storage/direct_uploads_controller"
4
5
 
5
6
  module SimpleActiveStorage
6
7
  # Your code goes here...
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_active_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aotianlong
@@ -52,6 +52,7 @@ files:
52
52
  - lib/generators/simple_active_storage/simple_active_storage_generator.rb
53
53
  - lib/generators/simple_active_storage/templates/simple_active_storage.rb
54
54
  - lib/simple_active_storage.rb
55
+ - lib/simple_active_storage/direct_uploads_controller.rb
55
56
  - lib/simple_active_storage/railtie.rb
56
57
  - lib/simple_active_storage/url.rb
57
58
  - lib/simple_active_storage/variation.rb