activestorage_qinium 0.4.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 +4 -4
- data/lib/active_storage/service/qinium_service.rb +31 -10
- data/lib/active_storage_qinium/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: '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)
|
|
@@ -132,25 +132,46 @@ module ActiveStorage
|
|
|
132
132
|
|
|
133
133
|
def url(key, **options)
|
|
134
134
|
instrument :url, key: key do |payload|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
|
142
160
|
url = if config.public
|
|
143
161
|
url_encoded_key = key.split("/").map { |x| CGI.escape(x) }.join("/")
|
|
144
|
-
|
|
162
|
+
base_url = "#{protocol}://#{domain}/#{url_encoded_key}"
|
|
163
|
+
query_params.any? ? "#{base_url}?#{query_params.join('&')}" : base_url
|
|
145
164
|
else
|
|
146
165
|
expires_in = options[:expires_in] ||
|
|
147
166
|
Rails.application.config.active_storage.service_urls_expire_in ||
|
|
148
167
|
3600
|
|
168
|
+
# 对于私有资源,需要将查询参数传递给授权 URL 生成
|
|
169
|
+
fop = query_params.join('&') if query_params.any?
|
|
149
170
|
Qinium::Auth.authorize_download_url(domain, key,
|
|
150
171
|
access_key, secret_key,
|
|
151
172
|
schema: protocol, fop: fop, expires_in: expires_in)
|
|
152
173
|
end
|
|
153
|
-
|
|
174
|
+
|
|
154
175
|
payload[:url] = url
|
|
155
176
|
url
|
|
156
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.
|
|
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: 2025-
|
|
11
|
+
date: 2025-12-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: qinium
|