jpsclient 2.0.4 → 2.1.0

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: 9f63634bc5ba1fbebefa6a5e9a25ab1d9deec1aff9f9af60c0bf198da5632e66
4
- data.tar.gz: 0ddf4fe34aaf7cafedf37b2e10a5c559d9066973845859aed72f107e0d5f8edb
3
+ metadata.gz: 981dafda351203d47d3137bf2e81b0e4e25bb188f23f0842b6b979379d671b23
4
+ data.tar.gz: e779e003a1ba7d260e146feecc07e5484580e38daa12c94a2613ebed0dc2cf8f
5
5
  SHA512:
6
- metadata.gz: d5f01fe231fc63335703a762349a746eec57cf412446bc38dd9c2d456514137f5908c21a45f069b291c8a6575bd38de24293da6e30a753e761a40842168e6920
7
- data.tar.gz: b21b6c17c5ae707da4b540b75751753fddf70555e3d24ab7d51499424262e2bdc6b4a10c60d45700646b6200436b15e3d93470e59246769ae6ebc15fb10514a5
6
+ metadata.gz: e18798568d960240dbb7a9d0929f085ecedd5cc1ecaf7abf8ab342dbef25d201a57b39e10d3718e610f6af5698010634a716bacbc0b651bde3e14b1e9e1533be
7
+ data.tar.gz: e0f48d126f0ac6806f7e4263f1d329c67c3d83193865b4a2040c940c7ca3e6e99bf56d87280dfd4b2c38c71e39c1fb4f00de0c001e15c3facfbbae86fd7df5f8
@@ -0,0 +1,232 @@
1
+ module JPSClient
2
+ module API
3
+ # Android JKS 证书相关 API
4
+ # 处理 /api/android_jks/* 路径的所有接口
5
+ #
6
+ # 支持的功能:
7
+ # - 创建 JKS 证书(异步)
8
+ # - 更新 JKS 证书信息
9
+ # - 删除 JKS 证书
10
+ # - 获取 JKS 证书列表
11
+ # - 获取 JKS 证书详情
12
+ # - 重命名 JKS 证书(异步)
13
+ # - APK 重签名(异步)
14
+ module AndroidJks
15
+
16
+ # 创建 Android JKS 证书(异步接口)
17
+ #
18
+ # @param alias_name [String] 证书别名(必填)
19
+ # @param store_password [String] keystore 密码,为空则自动生成
20
+ # @param key_password [String] key 密码,为空则与 store_password 一致
21
+ # @param validity [Integer] 有效期(天),默认 36500
22
+ # @param distinguished_name [Hash] DN 信息,如 {CN: "xxx", O: "xxx"}
23
+ # @param bundle_id [String] 包名(必填)
24
+ # @param google_account [String] Google 开发者账号
25
+ # @param project_id [String] 关联项目 ID
26
+ # @param remark [String] 备注
27
+ # @return [Hash] API 响应(异步任务)
28
+ def create_android_jks(alias_name:, bundle_id:, store_password: nil, key_password: nil, validity: nil,
29
+ distinguished_name: nil, google_account: nil,
30
+ project_id: nil, remark: nil)
31
+ config = @request_config && @request_config["android_jks_create"]
32
+ raise JPSClient::ExceptionError, "Missing config for android_jks_create" unless config && config["url"]
33
+ path = config["url"]
34
+
35
+ body_params = { aliasName: alias_name, bundleId: bundle_id }
36
+ body_params[:storePassword] = store_password if store_password
37
+ body_params[:keyPassword] = key_password if key_password
38
+ body_params[:validity] = validity if validity
39
+ body_params[:distinguishedName] = distinguished_name if distinguished_name
40
+ body_params[:googleAccount] = google_account if google_account
41
+ body_params[:projectId] = project_id if project_id
42
+ body_params[:remark] = remark if remark
43
+
44
+ response = @http_client.post(path, body: body_params)
45
+ result = JPSClient::Response.new(response)
46
+
47
+ if result.need_login?
48
+ do_login(force_login: true)
49
+ response = @http_client.post(path, body: body_params)
50
+ result = JPSClient::Response.new(response)
51
+ end
52
+
53
+ return result.to_h
54
+ end
55
+
56
+ # 更新 Android JKS 证书信息
57
+ #
58
+ # @param id [String] JKS ID(必填)
59
+ # @param bundle_id [String] 包名
60
+ # @param google_account [String] Google 开发者账号
61
+ # @param project_id [String] 关联项目 ID
62
+ # @param remark [String] 备注
63
+ # @return [Hash] API 响应
64
+ def update_android_jks(id:, bundle_id: nil, google_account: nil, project_id: nil, remark: nil)
65
+ config = @request_config && @request_config["android_jks_update"]
66
+ raise JPSClient::ExceptionError, "Missing config for android_jks_update" unless config && config["url"]
67
+ path = config["url"]
68
+
69
+ body_params = { id: id }
70
+ body_params[:bundleId] = bundle_id if bundle_id
71
+ body_params[:googleAccount] = google_account if google_account
72
+ body_params[:projectId] = project_id if project_id
73
+ body_params[:remark] = remark if remark
74
+
75
+ response = @http_client.post(path, body: body_params)
76
+ result = JPSClient::Response.new(response)
77
+
78
+ if result.need_login?
79
+ do_login(force_login: true)
80
+ response = @http_client.post(path, body: body_params)
81
+ result = JPSClient::Response.new(response)
82
+ end
83
+
84
+ return result.to_h
85
+ end
86
+
87
+ # 删除 Android JKS 证书
88
+ #
89
+ # @param id [String] JKS ID(必填)
90
+ # @return [Hash] API 响应
91
+ def delete_android_jks(id:)
92
+ config = @request_config && @request_config["android_jks_delete"]
93
+ raise JPSClient::ExceptionError, "Missing config for android_jks_delete" unless config && config["url"]
94
+ path = config["url"]
95
+
96
+ body_params = { id: id }
97
+
98
+ response = @http_client.post(path, body: body_params)
99
+ result = JPSClient::Response.new(response)
100
+
101
+ if result.need_login?
102
+ do_login(force_login: true)
103
+ response = @http_client.post(path, body: body_params)
104
+ result = JPSClient::Response.new(response)
105
+ end
106
+
107
+ return result.to_h
108
+ end
109
+
110
+ # 获取 Android JKS 证书列表
111
+ #
112
+ # @param page_no [Integer] 当前页数(必填)
113
+ # @param page_size [Integer] 每页记录数(必填)
114
+ # @param alias_name [String] 证书别名(可选)
115
+ # @param google_account [String] Google 开发者账号(可选)
116
+ # @param project_id [String] 关联项目 ID(可选)
117
+ # @return [Hash] API 响应,data 包含 list 数组和 total 总数
118
+ def get_android_jks_list(page_no: 1, page_size: 20, alias_name: nil, google_account: nil, project_id: nil)
119
+ config = @request_config && @request_config["android_jks_list"]
120
+ raise JPSClient::ExceptionError, "Missing config for android_jks_list" unless config && config["url"]
121
+ path = config["url"]
122
+
123
+ get_params = { pageNo: page_no, pageSize: page_size }
124
+ get_params[:aliasName] = alias_name if alias_name
125
+ get_params[:googleAccount] = google_account if google_account
126
+ get_params[:projectId] = project_id if project_id
127
+
128
+ response = @http_client.get(path, params: get_params)
129
+ result = JPSClient::Response.new(response)
130
+
131
+ if result.need_login?
132
+ do_login(force_login: true)
133
+ response = @http_client.get(path, params: get_params)
134
+ result = JPSClient::Response.new(response)
135
+ end
136
+
137
+ return result.to_h
138
+ end
139
+
140
+ # 获取 Android JKS 证书详情
141
+ #
142
+ # @param bundle_id [String] 包名(必填)
143
+ # @return [Hash] API 响应,data 包含 id、aliasName、bundleId、jksFileUrl、storePassword、keyPassword
144
+ def get_android_jks_detail(bundle_id:)
145
+ config = @request_config && @request_config["android_jks_detail"]
146
+ raise JPSClient::ExceptionError, "Missing config for android_jks_detail" unless config && config["url"]
147
+ path = config["url"]
148
+
149
+ get_params = { bundleId: bundle_id }
150
+
151
+ response = @http_client.get(path, params: get_params)
152
+ result = JPSClient::Response.new(response)
153
+
154
+ if result.need_login?
155
+ do_login(force_login: true)
156
+ response = @http_client.get(path, params: get_params)
157
+ result = JPSClient::Response.new(response)
158
+ end
159
+
160
+ return result.to_h
161
+ end
162
+
163
+ # 重命名 Android JKS 证书(异步接口)
164
+ #
165
+ # @param id [String] JKS 证书 ID(必填)
166
+ # @param new_alias [String] 新别名(必填)
167
+ # @param new_store_password [String] 新 storePassword(必填)
168
+ # @return [Hash] API 响应(异步任务)
169
+ def rename_android_jks(id:, new_alias:, new_store_password:)
170
+ config = @request_config && @request_config["android_jks_rename"]
171
+ raise JPSClient::ExceptionError, "Missing config for android_jks_rename" unless config && config["url"]
172
+ path = config["url"]
173
+
174
+ body_params = {
175
+ id: id,
176
+ newAlias: new_alias,
177
+ newStorePassword: new_store_password
178
+ }
179
+
180
+ response = @http_client.post(path, body: body_params)
181
+ result = JPSClient::Response.new(response)
182
+
183
+ if result.need_login?
184
+ do_login(force_login: true)
185
+ response = @http_client.post(path, body: body_params)
186
+ result = JPSClient::Response.new(response)
187
+ end
188
+
189
+ return result.to_h
190
+ end
191
+
192
+ # APK 重签名(异步接口)
193
+ #
194
+ # @param input_s3_key [String] 输入 APK 文件的 S3 Key(必填)
195
+ # @param output_s3_key [String] 输出 APK 文件的 S3 Key(必填)
196
+ # @param new_package [String] 新的包名(必填)
197
+ # @param jks_id [String] JKS 证书 ID(必填)
198
+ # @param s3_bucket [String] S3 Bucket,默认 pgy-resource-new
199
+ # @param use_aapt2 [Boolean] 是否使用 aapt2,默认 true
200
+ # @param skip_verify [Boolean] 是否跳过签名验证,默认 false
201
+ # @return [Hash] API 响应(异步任务)
202
+ def rewrite_apk(input_s3_key:, output_s3_key:, new_package:, jks_id:,
203
+ s3_bucket: nil, use_aapt2: nil, skip_verify: nil)
204
+ config = @request_config && @request_config["android_jks_rewrite_apk"]
205
+ raise JPSClient::ExceptionError, "Missing config for android_jks_rewrite_apk" unless config && config["url"]
206
+ path = config["url"]
207
+
208
+ body_params = {
209
+ inputS3Key: input_s3_key,
210
+ outputS3Key: output_s3_key,
211
+ newPackage: new_package,
212
+ jksId: jks_id
213
+ }
214
+ body_params[:s3Bucket] = s3_bucket if s3_bucket
215
+ body_params[:useAapt2] = use_aapt2 unless use_aapt2.nil?
216
+ body_params[:skipVerify] = skip_verify unless skip_verify.nil?
217
+
218
+ response = @http_client.post(path, body: body_params)
219
+ result = JPSClient::Response.new(response)
220
+
221
+ if result.need_login?
222
+ do_login(force_login: true)
223
+ response = @http_client.post(path, body: body_params)
224
+ result = JPSClient::Response.new(response)
225
+ end
226
+
227
+ return result.to_h
228
+ end
229
+
230
+ end
231
+ end
232
+ end
@@ -9,6 +9,7 @@ require 'jpsclient/auth/token'
9
9
  require 'jpsclient/utils/logger'
10
10
 
11
11
  # 加载 API 模块
12
+ require 'jpsclient/api/android_jks'
12
13
  require 'jpsclient/api/app_level'
13
14
  require 'jpsclient/api/app_resource'
14
15
  # require 'jpsclient/api/app_resource_version' # 已移除 - API不存在
@@ -98,6 +99,7 @@ module JPSClient
98
99
 
99
100
  class Client
100
101
  # 引入各个 API 模块
102
+ include API::AndroidJks
101
103
  include API::AppLevel
102
104
  include API::AppResource
103
105
  # include API::AppResourceVersion # 已移除 - API不存在
@@ -3,6 +3,8 @@ require 'typhoeus'
3
3
  require 'thread'
4
4
  require 'etc'
5
5
  require 'digest'
6
+ require 'cgi'
7
+ require 'uri'
6
8
  require 'jpsclient/base/exception'
7
9
  require 'jpsclient/upload/upload_config'
8
10
  require 'jpsclient/upload/upload_progress'
@@ -39,12 +41,13 @@ module JPSClient
39
41
  @upload_failed = false
40
42
  end
41
43
 
42
- def upload_file(binary_file:nil, isAttach:false)
44
+ def upload_file(binary_file:nil, isAttach:false, enable_cloudflare:false)
43
45
 
44
46
  raise ExceptionError, "上传文件不能为空" if binary_file.nil? || !File.exist?(binary_file)
45
47
 
46
48
  @upload_binary_file = binary_file
47
49
  @file_size = File.size(@upload_binary_file)
50
+ @enable_cloudflare = enable_cloudflare
48
51
 
49
52
  # 处理空文件
50
53
  if @file_size == 0
@@ -89,6 +92,11 @@ module JPSClient
89
92
  upload_config: @upload_config
90
93
  )
91
94
 
95
+ # Debug 模式下打印初始化结果
96
+ if ENV['PINDO_DEBUG'] == '1'
97
+ puts "[PINDO_DEBUG] init_file_multipart 返回: #{init_result.inspect}"
98
+ end
99
+
92
100
  if init_result.nil? || !init_result.dig("data", "upload_id")
93
101
  raise ExceptionError, "初始化上传失败,请检查网络或服务器状态"
94
102
  end
@@ -291,7 +299,21 @@ module JPSClient
291
299
  return
292
300
  end
293
301
 
294
- upload_url = sign_result["data"]["url"]
302
+ original_url = sign_result["data"]["url"]
303
+ upload_url = original_url
304
+
305
+ # 如果启用 Cloudflare 加速,转换 URL
306
+ if @enable_cloudflare
307
+ upload_url = convert_to_cloudflare_fetch_url(original_url)
308
+ end
309
+
310
+ # Debug 模式下打印加速前后 URL 对比
311
+ if ENV['PINDO_DEBUG'] == '1'
312
+ puts "[PINDO_DEBUG] 分片 ##{part_no} 原始 URL: #{original_url}"
313
+ if @enable_cloudflare
314
+ puts "[PINDO_DEBUG] 分片 ##{part_no} 加速 URL: #{upload_url}"
315
+ end
316
+ end
295
317
 
296
318
  # 计算分片数据范围(使用配置的分片大小)
297
319
  chunk_size = @upload_config.chunk_size_bytes
@@ -401,7 +423,29 @@ module JPSClient
401
423
  end
402
424
  end
403
425
 
426
+ # 将 S3 预签名 URL 转换为 Cloudflare fetch 代理 URL
427
+ # 格式: https://fetch.goosoul.dev/{filename}?url={percent_encoded_original_url}
428
+ def convert_to_cloudflare_fetch_url(original_url)
429
+ return original_url if original_url.nil? || original_url.empty?
404
430
 
431
+ begin
432
+ uri = URI.parse(original_url)
433
+
434
+ # 从路径中提取文件名
435
+ path_parts = uri.path.split('/')
436
+ filename = path_parts.last || 'file'
437
+
438
+ # 对原始完整 URL 进行 percent 编码
439
+ encoded_url = CGI.escape(original_url)
440
+
441
+ # 构建 Cloudflare fetch URL
442
+ "https://fetch.goosoul.dev/#{filename}?url=#{encoded_url}"
443
+ rescue => e
444
+ # 解析失败时返回原始 URL
445
+ Logger.instance.info("URL 转换失败: #{e.message},使用原始 URL")
446
+ original_url
447
+ end
448
+ end
405
449
 
406
450
  end
407
- end
451
+ end
@@ -58,7 +58,7 @@ module JPSClient
58
58
  attach_url: json_config['attach_url'] || "attach_file/",
59
59
  upload_type: json_config['upload_type'] || "s3",
60
60
  concurrent_workers: concurrent_workers,
61
- chunk_size_mb: json_config['chunk_size_mb'] || 5,
61
+ chunk_size_mb: json_config['chunk_size_mb'] || 10,
62
62
  max_retry_times: json_config['max_retry_times'] || 6, # 每个分片重试6次
63
63
  timeout_seconds: json_config['timeout_seconds'] || 600, # 单个分片超时10分钟
64
64
  media_region: json_config['media_region'] || "ap-east-1",
@@ -1,3 +1,3 @@
1
1
  module JPSClient
2
- VERSION = "2.0.4"
3
- end
2
+ VERSION = '2.1.0'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpsclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Your Name
@@ -161,6 +161,7 @@ files:
161
161
  - LICENSE
162
162
  - bin/jpsclient
163
163
  - lib/jpsclient.rb
164
+ - lib/jpsclient/api/android_jks.rb
164
165
  - lib/jpsclient/api/app_level.rb
165
166
  - lib/jpsclient/api/app_resource.rb
166
167
  - lib/jpsclient/api/apple_account.rb