jpsclient 2.7.3 → 2.7.5
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: b7014fe7a27b5b18567a2026f0df7f02efc5cb41fd9756e031377f8d7af74d65
|
|
4
|
+
data.tar.gz: e0e02d786ede3bdb12b5d5f4d42f4a65d9414420835de19230b638be24f4bc66
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed31e0a4b90af88a0a21596ea29aaa29442be00defb71bc90a05b750bc9d304cbf08aec40dab57d9fcbc20f50ddeabb013564cdfc0273ff3d009fc7ae44768e8
|
|
7
|
+
data.tar.gz: 7573c0e55b1be5fa61290621f678cfc038e617919407b0b4e1e0d81d31fea909fd6adb31b867ebf77f03d4bcf647bf4c269883716cae501a7344a1d55a6f3f4a
|
data/lib/jpsclient/api/file.rb
CHANGED
|
@@ -6,7 +6,10 @@ module JPSClient
|
|
|
6
6
|
|
|
7
7
|
# 初始化多部分上传
|
|
8
8
|
def init_file_multipart(s3_key:, content_type: "", upload_config:)
|
|
9
|
-
|
|
9
|
+
config = @request_config && @request_config["file_init_multipart"]
|
|
10
|
+
raise JPSClient::ExceptionError, "Missing config for file_init_multipart" unless config && config["url"]
|
|
11
|
+
|
|
12
|
+
path = config["url"]
|
|
10
13
|
|
|
11
14
|
body_params = {
|
|
12
15
|
s3Key: s3_key,
|
|
@@ -24,7 +27,10 @@ module JPSClient
|
|
|
24
27
|
# @param upload_config [UploadConfig] 上传配置
|
|
25
28
|
# @return [Hash] 包含预签名URL的响应
|
|
26
29
|
def get_simple_sign_url(s3_key:, upload_config:)
|
|
27
|
-
|
|
30
|
+
config = @request_config && @request_config["file_sign_url"]
|
|
31
|
+
raise JPSClient::ExceptionError, "Missing config for file_sign_url" unless config && config["url"]
|
|
32
|
+
|
|
33
|
+
path = config["url"]
|
|
28
34
|
|
|
29
35
|
body_params = {
|
|
30
36
|
s3Key: s3_key,
|
|
@@ -38,7 +44,10 @@ module JPSClient
|
|
|
38
44
|
|
|
39
45
|
# 获取分片预签名URL
|
|
40
46
|
def get_file_sign_url(s3_key:, upload_id:, part_id:, upload_config:)
|
|
41
|
-
|
|
47
|
+
config = @request_config && @request_config["file_sign_url"]
|
|
48
|
+
raise JPSClient::ExceptionError, "Missing config for file_sign_url" unless config && config["url"]
|
|
49
|
+
|
|
50
|
+
path = config["url"]
|
|
42
51
|
|
|
43
52
|
body_params = {
|
|
44
53
|
s3Key: s3_key,
|
|
@@ -54,7 +63,10 @@ module JPSClient
|
|
|
54
63
|
|
|
55
64
|
# 完成多部分上传
|
|
56
65
|
def complete_file_multipart(s3_key:, upload_id:, upload_config:)
|
|
57
|
-
|
|
66
|
+
config = @request_config && @request_config["file_complete_multipart"]
|
|
67
|
+
raise JPSClient::ExceptionError, "Missing config for file_complete_multipart" unless config && config["url"]
|
|
68
|
+
|
|
69
|
+
path = config["url"]
|
|
58
70
|
|
|
59
71
|
body_params = {
|
|
60
72
|
s3Key: s3_key,
|
|
@@ -61,7 +61,6 @@ module JPSClient
|
|
|
61
61
|
# @option params [String] :projectPackageId 项目包ID
|
|
62
62
|
# @return [Hash] API响应
|
|
63
63
|
def upload_nuget_package(projectId:nil, params:nil)
|
|
64
|
-
puts "========1111 upload_nuget_package" if JPSClient.debug?
|
|
65
64
|
config = @request_config && @request_config["project_package_upload_nuget"]
|
|
66
65
|
raise JPSClient::ExceptionError, "Missing config for project_package_upload_nuget" unless config && config["url"]
|
|
67
66
|
path = config["url"]
|
|
@@ -79,6 +79,8 @@ module JPSClient
|
|
|
79
79
|
puts "文件路径: #{@upload_binary_file}"
|
|
80
80
|
puts "文件大小: #{total_mb}M"
|
|
81
81
|
puts "上传路径: #{s3_key}"
|
|
82
|
+
puts "存储桶: #{@upload_config.bucket_name}"
|
|
83
|
+
puts "区域: #{@upload_config.region}"
|
|
82
84
|
puts
|
|
83
85
|
puts "切片大小: #{@upload_config.chunk_size_mb}MB"
|
|
84
86
|
|
|
@@ -98,12 +100,11 @@ module JPSClient
|
|
|
98
100
|
puts "[JPS_DEBUG] init_file_multipart 返回: #{init_result.inspect}"
|
|
99
101
|
end
|
|
100
102
|
|
|
101
|
-
|
|
103
|
+
upload_id = multipart_upload_id(init_result)
|
|
104
|
+
if init_result.nil? || upload_id.nil?
|
|
102
105
|
raise ExceptionError, init_multipart_error_message(init_result)
|
|
103
106
|
end
|
|
104
107
|
|
|
105
|
-
upload_id = init_result["data"]["upload_id"]
|
|
106
|
-
|
|
107
108
|
# 准备分片任务队列
|
|
108
109
|
@tasks_queue = Queue.new
|
|
109
110
|
@worker_threads = []
|
|
@@ -150,7 +151,7 @@ module JPSClient
|
|
|
150
151
|
|
|
151
152
|
if complete_result && (complete_result["code"] == 0 || complete_result["code"] == 200)
|
|
152
153
|
# 返回 URL 字符串以保持向后兼容
|
|
153
|
-
upload_result = complete_result
|
|
154
|
+
upload_result = uploaded_file_url(complete_result, s3_key)
|
|
154
155
|
Logger.instance.fancyinfo_success("文件#{@upload_binary_file} 上传成功! 😎😎😎")
|
|
155
156
|
else
|
|
156
157
|
upload_result = nil
|
|
@@ -323,13 +324,13 @@ module JPSClient
|
|
|
323
324
|
upload_config: @upload_config
|
|
324
325
|
)
|
|
325
326
|
|
|
326
|
-
|
|
327
|
+
original_url = signed_upload_url(sign_result)
|
|
328
|
+
if original_url.nil?
|
|
327
329
|
# Logger.instance.info("分片 ##{part_no} 获取上传URL失败") # 避免打断进度条
|
|
328
330
|
handle_retry(upload_params_item, "获取上传URL失败")
|
|
329
331
|
return
|
|
330
332
|
end
|
|
331
333
|
|
|
332
|
-
original_url = sign_result["data"]["url"]
|
|
333
334
|
upload_url = original_url
|
|
334
335
|
|
|
335
336
|
# 如果启用 Cloudflare 加速,转换 URL
|
|
@@ -431,13 +432,34 @@ module JPSClient
|
|
|
431
432
|
end
|
|
432
433
|
end
|
|
433
434
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
435
|
+
def calculate_chunk_timeout(chunk_size)
|
|
436
|
+
# 使用配置的 timeout_seconds 作为单个分片的超时时间
|
|
437
|
+
# 默认600秒(10分钟)
|
|
438
|
+
@upload_config.timeout_seconds || 600
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def multipart_upload_id(init_result)
|
|
442
|
+
init_result&.dig("data", "upload_id") || init_result&.dig("data", "uploadId")
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
def signed_upload_url(sign_result)
|
|
446
|
+
data = sign_result&.dig("data")
|
|
447
|
+
return nil unless data.is_a?(Hash)
|
|
448
|
+
|
|
449
|
+
data["url"] || data["signUrl"] || data["sign_url"] ||
|
|
450
|
+
data["apiGatewayUrl"] || data["api_gateway_url"]
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
def uploaded_file_url(complete_result, s3_key)
|
|
454
|
+
data = complete_result&.dig("data")
|
|
455
|
+
return s3_key unless data.is_a?(Hash)
|
|
456
|
+
|
|
457
|
+
data["url"] || data["httpUrl"] || data["http_url"] ||
|
|
458
|
+
data["apiGatewayUrl"] || data["api_gateway_url"] ||
|
|
459
|
+
data["s3Url"] || data["s3_url"] || s3_key
|
|
460
|
+
end
|
|
439
461
|
|
|
440
|
-
|
|
462
|
+
def handle_retry(upload_params_item, error_reason)
|
|
441
463
|
part_no = upload_params_item["partNo"]
|
|
442
464
|
@progress_bar.delete_upload_index(upload_part:part_no)
|
|
443
465
|
|
|
@@ -241,13 +241,12 @@ module JPSClient
|
|
|
241
241
|
upload_config: @upload_config
|
|
242
242
|
)
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
upload_url = signed_upload_url(sign_result)
|
|
245
|
+
unless upload_url
|
|
245
246
|
handle_retry(task_item, "获取预签名 URL 失败")
|
|
246
247
|
return
|
|
247
248
|
end
|
|
248
249
|
|
|
249
|
-
upload_url = sign_result["data"]["url"]
|
|
250
|
-
|
|
251
250
|
# 读取文件
|
|
252
251
|
begin
|
|
253
252
|
file_content = File.binread(file_path)
|
|
@@ -276,8 +275,7 @@ module JPSClient
|
|
|
276
275
|
response = request.run
|
|
277
276
|
|
|
278
277
|
if response.success?
|
|
279
|
-
|
|
280
|
-
file_url = "https://#{@upload_config.media_bucket_name}.s3.#{@upload_config.media_region}.amazonaws.com/#{s3_key}"
|
|
278
|
+
file_url = uploaded_media_url(sign_result, s3_key)
|
|
281
279
|
|
|
282
280
|
# 记录成功结果
|
|
283
281
|
@results_mutex.synchronize do
|
|
@@ -348,6 +346,34 @@ module JPSClient
|
|
|
348
346
|
[[calculated, 30].max, 300].min
|
|
349
347
|
end
|
|
350
348
|
|
|
349
|
+
def signed_upload_url(sign_result)
|
|
350
|
+
data = sign_result&.dig("data")
|
|
351
|
+
return nil unless data.is_a?(Hash)
|
|
352
|
+
|
|
353
|
+
data["url"] || data["signUrl"] || data["sign_url"] ||
|
|
354
|
+
data["apiGatewayUrl"] || data["api_gateway_url"]
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def uploaded_media_url(sign_result, s3_key)
|
|
358
|
+
data = sign_result&.dig("data")
|
|
359
|
+
if data.is_a?(Hash)
|
|
360
|
+
url = data["fileUrl"] || data["file_url"] ||
|
|
361
|
+
data["staticUrl"] || data["static_url"] ||
|
|
362
|
+
data["httpUrl"] || data["http_url"] ||
|
|
363
|
+
data["url"]
|
|
364
|
+
return url unless url.to_s.empty?
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
"#{static_base_url}/#{s3_key}"
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
def static_base_url
|
|
371
|
+
bucket_name = @upload_config.media_bucket_name.to_s
|
|
372
|
+
return "https://jps-static.devtestapp.com" if bucket_name == "jps-resource"
|
|
373
|
+
|
|
374
|
+
"https://pgy-static.devtestapp.com"
|
|
375
|
+
end
|
|
376
|
+
|
|
351
377
|
# 检查是否上传失败
|
|
352
378
|
def upload_failed?
|
|
353
379
|
@upload_failed_mutex.synchronize { @upload_failed }
|
data/lib/jpsclient/version.rb
CHANGED