x 0.15.3 → 0.15.4
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/CHANGELOG.md +3 -0
- data/lib/x/media_uploader.rb +11 -10
- data/lib/x/version.rb +1 -1
- data/sig/x.rbs +2 -2
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 731556dfa3e6417d5e0ea9305d6a6b87cc87bd360d71277df0b3dd1c5c8400b5
|
4
|
+
data.tar.gz: a1170fee36003355b65fe7a6a2732eb750ab0681bae74539d3f1eb17bfd96f65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec96213eaf3a727ba153c9df7f4f92649b45d3089944d3c02bf6c56960a593845818b7e9e4c947b0317dc6ec4325c7563652d9bcebd911c677171ba1d397fd21
|
7
|
+
data.tar.gz: dc3d6fb361ec7de40ac47d065c3840dd4972f7a32ebb17ed3969b56fc6257272d82c66d035b298956ac1209548c54e46530c75dbea3d23b8ebcd341480670a41
|
data/CHANGELOG.md
CHANGED
data/lib/x/media_uploader.rb
CHANGED
@@ -30,7 +30,7 @@ module X
|
|
30
30
|
media = init(client:, file_path:, media_type:, media_category:)
|
31
31
|
chunk_size = chunk_size_mb * BYTES_PER_MB
|
32
32
|
append(client:, file_paths: split(file_path, chunk_size), media:, media_type:, boundary:)
|
33
|
-
client.post("media/upload
|
33
|
+
client.post("media/upload/#{media["id"]}/finalize")&.fetch("data")
|
34
34
|
end
|
35
35
|
|
36
36
|
def await_processing(client:, media:)
|
@@ -77,24 +77,23 @@ module X
|
|
77
77
|
|
78
78
|
def init(client:, file_path:, media_type:, media_category:)
|
79
79
|
total_bytes = File.size(file_path)
|
80
|
-
|
81
|
-
client.post("media/upload
|
80
|
+
data = {media_type:, media_category:, total_bytes:}.to_json
|
81
|
+
client.post("media/upload/initialize", data)&.fetch("data")
|
82
82
|
end
|
83
83
|
|
84
84
|
def append(client:, file_paths:, media:, media_type:, boundary: SecureRandom.hex)
|
85
85
|
threads = file_paths.map.with_index do |file_path, index|
|
86
86
|
Thread.new do
|
87
|
-
upload_body = construct_upload_body(file_path:, media_type:, boundary:)
|
88
|
-
query = "command=APPEND&media_id=#{media["id"]}&segment_index=#{index}"
|
87
|
+
upload_body = construct_upload_body(file_path:, media_type:, segment_index: index, boundary:)
|
89
88
|
headers = {"Content-Type" => "multipart/form-data, boundary=#{boundary}"}
|
90
|
-
upload_chunk(client:,
|
89
|
+
upload_chunk(client:, media_id: media["id"], upload_body:, file_path:, headers:)
|
91
90
|
end
|
92
91
|
end
|
93
92
|
threads.each(&:join)
|
94
93
|
end
|
95
94
|
|
96
|
-
def upload_chunk(client:,
|
97
|
-
client.post("media/upload
|
95
|
+
def upload_chunk(client:, media_id:, upload_body:, file_path:, headers: {})
|
96
|
+
client.post("media/upload/#{media_id}/append", upload_body, headers:)
|
98
97
|
rescue NetworkError, ServerError
|
99
98
|
retries ||= 0
|
100
99
|
((retries += 1) < MAX_RETRIES) ? retry : raise
|
@@ -108,8 +107,10 @@ module X
|
|
108
107
|
Dir.delete(dirname) if Dir.empty?(dirname)
|
109
108
|
end
|
110
109
|
|
111
|
-
def construct_upload_body(file_path:, media_type:, boundary: SecureRandom.hex)
|
112
|
-
"
|
110
|
+
def construct_upload_body(file_path:, media_type:, segment_index: nil, boundary: SecureRandom.hex)
|
111
|
+
body = ""
|
112
|
+
body += "--#{boundary}\r\nContent-Disposition: form-data; name=\"segment_index\"\r\n\r\n#{segment_index}\r\n" if segment_index
|
113
|
+
"#{body}--#{boundary}\r\n" \
|
113
114
|
"Content-Disposition: form-data; name=\"media\"; filename=\"#{File.basename(file_path)}\"\r\n" \
|
114
115
|
"Content-Type: #{media_type}\r\n\r\n" \
|
115
116
|
"#{File.binread(file_path)}\r\n" \
|
data/lib/x/version.rb
CHANGED
data/sig/x.rbs
CHANGED
@@ -275,9 +275,9 @@ module X
|
|
275
275
|
def split: (String file_path, Integer chunk_size) -> Array[String]
|
276
276
|
def init: (client: Client, file_path: String, media_type: String, media_category: String) -> untyped
|
277
277
|
def append: (client: Client, file_paths: Array[String], media: untyped, media_type: String, ?boundary: String) -> Array[String]
|
278
|
-
def upload_chunk: (client: Client,
|
278
|
+
def upload_chunk: (client: Client, media_id: String, upload_body: String, file_path: String, ?headers: Hash[String, String]) -> Integer?
|
279
279
|
def cleanup_file: (String file_path) -> Integer?
|
280
280
|
def finalize: (client: Client, media: untyped) -> untyped
|
281
|
-
def construct_upload_body: (file_path: String, media_type: String, ?boundary: String) -> String
|
281
|
+
def construct_upload_body: (file_path: String, media_type: String, ?segment_index: Integer, ?boundary: String) -> String
|
282
282
|
end
|
283
283
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: x
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.15.
|
4
|
+
version: 0.15.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Berlin
|
@@ -72,12 +72,13 @@ licenses:
|
|
72
72
|
- MIT
|
73
73
|
metadata:
|
74
74
|
allowed_push_host: https://rubygems.org
|
75
|
-
rubygems_mfa_required: 'true'
|
76
|
-
homepage_uri: https://sferik.github.io/x-ruby
|
77
|
-
source_code_uri: https://github.com/sferik/x-ruby
|
78
|
-
changelog_uri: https://github.com/sferik/x-ruby/blob/master/CHANGELOG.md
|
79
75
|
bug_tracker_uri: https://github.com/sferik/x-ruby/issues
|
76
|
+
changelog_uri: https://github.com/sferik/x-ruby/blob/master/CHANGELOG.md
|
80
77
|
documentation_uri: https://rubydoc.info/gems/x/
|
78
|
+
funding_uri: https://github.com/sponsors/sferik/
|
79
|
+
homepage_uri: https://sferik.github.io/x-ruby
|
80
|
+
rubygems_mfa_required: 'true'
|
81
|
+
source_code_uri: https://github.com/sferik/x-ruby
|
81
82
|
rdoc_options: []
|
82
83
|
require_paths:
|
83
84
|
- lib
|