imagekitio 2.0.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/active_storage/service/image_kit_io_service.rb +11 -8
- data/lib/imagekitio/api_service/file.rb +14 -1
- data/lib/imagekitio/constants/file.rb +1 -1
- data/lib/imagekitio/request.rb +24 -12
- data/lib/imagekitio/sdk/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c04894bf6eaea4759ee2ba7f6cee915f70a5608a37e8ded7537f6a1dcd7b06a3
|
4
|
+
data.tar.gz: bcfa613b654bfc45c9a04ef97565754dba6ab19f0c7654ecc508e79d9b7ab24f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed9fd632ab0ede984b852ec87320c851b4238aadd0a7c2fa7c00a89daa699923d9bea1a36e9c0960fa5d142a985b0d68a1ce8dbed4e70e100811ef242376090c
|
7
|
+
data.tar.gz: 83b14958b9c405f4e333e52ed9bb8f946c65649ae56c3209848b47d29af075f5f192bcd1b3145955710319592e8c4e75161df16168f04b1ea533208596faeb00
|
data/README.md
CHANGED
@@ -13,14 +13,14 @@ ImageKit gem for Ruby on Rails that allows you to use real-time [image resizing]
|
|
13
13
|
Table of contents -
|
14
14
|
* [Installation](#Installation)
|
15
15
|
* [Initialization](#Initialization)
|
16
|
-
- [CarrierWave](#Carrierwave
|
17
|
-
- [ActiveStorage](#
|
16
|
+
- [CarrierWave](#Carrierwave)
|
17
|
+
- [ActiveStorage](#activeStorage)
|
18
18
|
* [URL Generation](#URL-generation)
|
19
19
|
* [File Upload](#File-Upload)
|
20
20
|
* [File Management](#File-Management)
|
21
21
|
* [Utility Functions](#Utility-functions)
|
22
22
|
* [Sample applications](#Sample-Application)
|
23
|
-
* [Upgrade to 2.
|
23
|
+
* [Upgrade to 2.x](#upgrade-to-2.x)
|
24
24
|
* [Support](#Support)
|
25
25
|
* [Links](#Links)
|
26
26
|
|
@@ -715,9 +715,9 @@ There are three sample apps:
|
|
715
715
|
|
716
716
|
Please see the sample applications in [here](https://github.com/imagekit-samples/quickstart).
|
717
717
|
|
718
|
-
## Upgrade to 2.
|
718
|
+
## Upgrade to 2.x
|
719
719
|
|
720
|
-
If you are upgrading to 2.
|
720
|
+
If you are upgrading to 2.x from version 1.x, make the following changes in your application:
|
721
721
|
|
722
722
|
- Remove config from environment file to initializer file as described [here](#Initialization).
|
723
723
|
- Include `ImageKitIo::CarrierWave` in uploader class(for Carrierwave).
|
@@ -3,7 +3,7 @@ require_relative './ik_file'
|
|
3
3
|
if defined? Rails
|
4
4
|
# Overwrite the ActiveStorage::Downloader's open method and remove the file integrity check constraint method verify_integrity_of
|
5
5
|
class DownloaderExtension < ::ActiveStorage::Downloader
|
6
|
-
def open(key, checksum:, name: "ActiveStorage-", tmpdir: nil)
|
6
|
+
def open(key, checksum:, name: "ActiveStorage-", tmpdir: nil, **options)
|
7
7
|
open_tempfile(name, tmpdir) do |file|
|
8
8
|
download key, file
|
9
9
|
# verify_integrity_of file, checksum: checksum
|
@@ -71,9 +71,11 @@ if defined? Rails
|
|
71
71
|
def upload(key, io, checksum: nil, **options)
|
72
72
|
instrument :upload, key: key, checksum: checksum do
|
73
73
|
blob = storage_blob(key)
|
74
|
-
response = client.upload_file(file: io, file_name: blob.filename.to_s)
|
74
|
+
response = client.upload_file(file: io, file_name: blob.filename.to_s, content_type: blob.content_type)
|
75
75
|
if response[:error].nil?
|
76
76
|
blob.update_columns(metadata: response[:response].transform_keys(&:to_sym))
|
77
|
+
else
|
78
|
+
raise Exception.new response[:error]
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
@@ -132,7 +134,7 @@ if defined? Rails
|
|
132
134
|
end
|
133
135
|
|
134
136
|
def url(key, filename: nil, content_type: '', **options)
|
135
|
-
image_kit_file(key).
|
137
|
+
generate_url(key, filename: filename, content_type: content_type, path: image_kit_file(key).path, **options)
|
136
138
|
end
|
137
139
|
|
138
140
|
def open(*args, **options, &block)
|
@@ -141,13 +143,14 @@ if defined? Rails
|
|
141
143
|
|
142
144
|
private
|
143
145
|
|
144
|
-
def private_url(key, expires_in:, filename:, disposition:, content_type:, **)
|
145
|
-
generate_url(key, expires_in: expires_in, filename: filename, disposition: disposition, content_type: content_type)
|
146
|
+
def private_url(key, expires_in:, filename:, disposition:, content_type:, **options)
|
147
|
+
generate_url(key, expires_in: expires_in, filename: filename, disposition: disposition, content_type: content_type, path: image_kit_file(key).path, **options)
|
146
148
|
end
|
147
149
|
|
148
|
-
def generate_url(key, expires_in:, filename:, content_type:, disposition
|
149
|
-
filename =
|
150
|
-
|
150
|
+
def generate_url(key, expires_in:, filename:, content_type:, disposition:, **options)
|
151
|
+
# filename = filename.to_s if filename.is_a? ActiveStorage::Filename
|
152
|
+
# options[:filename] = filename if filename
|
153
|
+
client.url(url_endpoint: config.url_endpoint, **options)
|
151
154
|
end
|
152
155
|
|
153
156
|
def client
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require_relative '../constant'
|
3
3
|
require_relative '../utils/option_validator'
|
4
|
+
require 'net/http/post/multipart'
|
4
5
|
|
5
6
|
module ImageKitIo
|
6
7
|
module ApiService
|
@@ -32,6 +33,7 @@ module ImageKitIo
|
|
32
33
|
raise ArgumentError, constants.MISSING_UPLOAD_FILE_PARAMETER unless file
|
33
34
|
raise ArgumentError, constants.MISSING_UPLOAD_FILE_PARAMETER unless file_name
|
34
35
|
|
36
|
+
content_type = options.delete(:content_type) || ''
|
35
37
|
options = format_to_json(options, :extensions, Array)
|
36
38
|
options = format_to_json(options, :custom_metadata, Hash)
|
37
39
|
options = validate_upload_options(options || {})
|
@@ -39,7 +41,12 @@ module ImageKitIo
|
|
39
41
|
raise ArgumentError, "Invalid Upload option"
|
40
42
|
else
|
41
43
|
headers = @req_obj.create_headers
|
42
|
-
payload =
|
44
|
+
payload = {
|
45
|
+
multipart: true,
|
46
|
+
file: file.is_a?(String) ? file : ::UploadIO.new(file, content_type, file_name),
|
47
|
+
fileName: file_name
|
48
|
+
}
|
49
|
+
payload.merge!(options)
|
43
50
|
url = "#{constants.BASE_URL}#{constants.UPLOAD}"
|
44
51
|
@req_obj.request("post", url, headers, payload)
|
45
52
|
end
|
@@ -157,6 +164,12 @@ module ImageKitIo
|
|
157
164
|
payload = { 'filePath': file_path, 'newFileName': new_file_name }.merge(request_formatter(options)).to_json
|
158
165
|
@req_obj.request('put', url, @req_obj.create_headers, payload)
|
159
166
|
end
|
167
|
+
|
168
|
+
|
169
|
+
private
|
170
|
+
def image_format?(type)
|
171
|
+
%(image/jpeg image/bmp image/apng image/avif image/gif image/ief image/svg+xml image/tiff image/x-icon image/rgb image/webp).include?(type)
|
172
|
+
end
|
160
173
|
end
|
161
174
|
end
|
162
175
|
end
|
@@ -5,7 +5,7 @@ module ImageKitIo
|
|
5
5
|
|
6
6
|
VALID_FILE_DETAIL_OPTIONS = ["fileID"]
|
7
7
|
|
8
|
-
VALID_UPLOAD_OPTIONS = %w[file file_name use_unique_file_name tags folder is_private_file custom_coordinates response_fields extensions webhook_url overwrite_file overwrite_AI_tags overwrite_custom_metadata custom_metadata mime overwrite_tags ]
|
8
|
+
VALID_UPLOAD_OPTIONS = %w[file file_name use_unique_file_name tags folder is_private_file custom_coordinates response_fields extensions webhook_url overwrite_file overwrite_AI_tags overwrite_custom_metadata custom_metadata mime overwrite_tags content_type ]
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/imagekitio/request.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "base64"
|
4
4
|
require "rest-client"
|
5
5
|
require "json"
|
6
|
+
require 'net/http/post/multipart'
|
6
7
|
require_relative './constant'
|
7
8
|
# Request requests and sends data from server
|
8
9
|
module ImageKitIo
|
@@ -33,28 +34,39 @@ module ImageKitIo
|
|
33
34
|
# request method communicates with server
|
34
35
|
def request(method, url, headers = create_headers, payload = nil)
|
35
36
|
headers ||= create_headers
|
36
|
-
response = {
|
37
|
+
response = {}
|
37
38
|
begin
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
if
|
39
|
+
if(method.downcase.to_sym == :post && payload.is_a?(Hash) && payload[:multipart])
|
40
|
+
uri = URI.parse(url)
|
41
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
42
|
+
http.use_ssl = (uri.scheme == 'https')
|
43
|
+
req = Net::HTTP::Post::Multipart.new uri.path, payload, headers
|
44
|
+
resp = http.request(req)
|
45
|
+
if resp.code.to_i == 400
|
46
|
+
raise RestClient::ExceptionWithResponse, OpenStruct.new(code: 400, body: resp.body)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
resp = RestClient::Request.new(method: method,
|
50
|
+
url: url,
|
51
|
+
headers: headers,
|
52
|
+
payload: payload).execute
|
53
|
+
end
|
54
|
+
if (resp.code.to_i >= 200) && (resp.code.to_i < 204)
|
55
|
+
content_type = resp.respond_to?(:headers) ? resp.headers[:content_type] : resp.content_type
|
56
|
+
if (content_type.include? "application/json")
|
45
57
|
response[:response] = JSON.parse(resp.body.to_s)
|
46
58
|
else
|
47
|
-
raise
|
59
|
+
raise RestClient::ExceptionWithResponse, OpenStruct.new(code: 404, body: resp.body)
|
48
60
|
end
|
49
|
-
elsif resp.code == 204
|
61
|
+
elsif resp.code.to_i == 204
|
50
62
|
response[:response] = {'success': true}
|
51
63
|
end
|
52
64
|
|
53
65
|
rescue RestClient::ExceptionWithResponse => err
|
54
|
-
response[:error] = if err.http_code == 404
|
66
|
+
response[:error] = if err.http_code.to_i == 404
|
55
67
|
{'message': err.response.to_s}
|
56
68
|
else
|
57
|
-
JSON.parse(err.response)
|
69
|
+
err.response.is_a?(OpenStruct) ? JSON.parse(err.response.body) : JSON.parse(err.response)
|
58
70
|
end
|
59
71
|
end
|
60
72
|
response
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imagekitio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ImageKit.io team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -78,6 +78,20 @@ dependencies:
|
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: 5.2.0
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: multipart-post
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.1.0
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.1.0
|
81
95
|
- !ruby/object:Gem::Dependency
|
82
96
|
name: rails
|
83
97
|
requirement: !ruby/object:Gem::Requirement
|