activestorage_qinium 0.3.0 → 0.4.1
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
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '08e39c5af245eba9281ed6e5013a0747c36d7da69620adaf2244d70847a3e648'
|
|
4
|
+
data.tar.gz: 1158e940e113c509c04e56e9a3a99fdeb1cb1aa88144123c3078378b21b0e3db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ab2a096e129d3bf26b14c7766479dbd8b4ed6cdbcf70ba49d99d60a677eb63f375a1f2fd74c88dfeede77fe3b8e121c807ff9b99f71a6bdfc87de9626811130
|
|
7
|
+
data.tar.gz: bfadf92e3ac9affddf56a48438ef49d5780cb04183c356c506a04443126526b15056c5b1d5959d4ec130bca24eb37e9a418d4c82ea3af2042c25acb44f076df8
|
|
@@ -10,7 +10,7 @@ module ActiveStorage
|
|
|
10
10
|
to: :config
|
|
11
11
|
|
|
12
12
|
def self.analyzers
|
|
13
|
-
[ActiveStorage::Analyzer::QiniumImageAnalyzer]
|
|
13
|
+
@analyzers ||= [ActiveStorage::Analyzer::QiniumImageAnalyzer]
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def initialize(options)
|
|
@@ -116,6 +116,12 @@ module ActiveStorage
|
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
+
def copy(source_bucket, source_key, target_bucket, target_key)
|
|
120
|
+
instrument :fetch, source_bucket: source_bucket, source_key: source_key, target_bucket: target_bucket, target_key: target_key do
|
|
121
|
+
qiniu.object.copy(source_bucket, source_key, target_bucket, target_key)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
119
125
|
def exist?(key)
|
|
120
126
|
instrument :exist, key: key do |payload|
|
|
121
127
|
answer = items_for(key).any?
|
|
@@ -126,25 +132,46 @@ module ActiveStorage
|
|
|
126
132
|
|
|
127
133
|
def url(key, **options)
|
|
128
134
|
instrument :url, key: key do |payload|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
# 根据七牛云文档:https://developer.qiniu.com/kodo/1659/download-setting
|
|
136
|
+
# 1. 使用 attname 参数可以让浏览器下载而不是打开
|
|
137
|
+
# 2. 使用 response-content-disposition 参数可以自定义 Content-Disposition 响应头
|
|
138
|
+
# 3. 使用 response-content-type 参数可以自定义 Content-Type 响应头
|
|
139
|
+
|
|
140
|
+
disposition = options[:disposition].to_s.downcase
|
|
141
|
+
content_type = options[:content_type]
|
|
142
|
+
|
|
143
|
+
# 构建查询参数
|
|
144
|
+
query_params = []
|
|
145
|
+
|
|
146
|
+
if options[:fop].present? # 内容预处理
|
|
147
|
+
query_params << options[:fop]
|
|
148
|
+
elsif disposition == "attachment" # 下载附件
|
|
149
|
+
attname = URI.encode_www_form_component (options[:filename] || key).to_s
|
|
150
|
+
query_params << "attname=#{attname}"
|
|
151
|
+
elsif disposition == "inline" # 预览(inline)
|
|
152
|
+
# 明确设置 Content-Disposition 为 inline,确保浏览器预览而不是下载
|
|
153
|
+
query_params << "response-content-disposition=inline"
|
|
154
|
+
# 如果提供了 content_type,也设置 Content-Type 响应头
|
|
155
|
+
# 这对于 PDF 文件特别重要,确保 Content-Type: application/pdf
|
|
156
|
+
query_params << "response-content-type=#{URI.encode_www_form_component(content_type)}" if content_type.present?
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# 构建 URL
|
|
136
160
|
url = if config.public
|
|
137
161
|
url_encoded_key = key.split("/").map { |x| CGI.escape(x) }.join("/")
|
|
138
|
-
|
|
162
|
+
base_url = "#{protocol}://#{domain}/#{url_encoded_key}"
|
|
163
|
+
query_params.any? ? "#{base_url}?#{query_params.join('&')}" : base_url
|
|
139
164
|
else
|
|
140
165
|
expires_in = options[:expires_in] ||
|
|
141
166
|
Rails.application.config.active_storage.service_urls_expire_in ||
|
|
142
167
|
3600
|
|
168
|
+
# 对于私有资源,需要将查询参数传递给授权 URL 生成
|
|
169
|
+
fop = query_params.join('&') if query_params.any?
|
|
143
170
|
Qinium::Auth.authorize_download_url(domain, key,
|
|
144
171
|
access_key, secret_key,
|
|
145
172
|
schema: protocol, fop: fop, expires_in: expires_in)
|
|
146
173
|
end
|
|
147
|
-
|
|
174
|
+
|
|
148
175
|
payload[:url] = url
|
|
149
176
|
url
|
|
150
177
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activestorage_qinium
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- xiaohui
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-12-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: qinium
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.
|
|
19
|
+
version: 0.4.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.
|
|
26
|
+
version: 0.4.0
|
|
27
27
|
description: Wraps the Qiniu Storage Service as an Active Storage service, support
|
|
28
28
|
muti-tenant settings. https://www.qiniu.com
|
|
29
29
|
email:
|
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
69
69
|
- !ruby/object:Gem::Version
|
|
70
70
|
version: '0'
|
|
71
71
|
requirements: []
|
|
72
|
-
rubygems_version: 3.
|
|
72
|
+
rubygems_version: 3.5.16
|
|
73
73
|
signing_key:
|
|
74
74
|
specification_version: 4
|
|
75
75
|
summary: A muti-tenant SDK wrap the Qiniu Storage Service as an Active Storage service
|