ZMediumToMarkdown 2.4.8 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/Helper.rb +1 -1
- data/lib/Post.rb +1 -13
- data/lib/Request.rb +33 -16
- 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: 3e2329fa42690e35efea3b0231c03949d460484e821f27b9a3da53fe43908906
|
4
|
+
data.tar.gz: 9636ba2e044114cda97780db906014f4bbe7859af23c3236cc79d8928040fffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1aad74dfa4a903110456dd1fab95ba2b4c2b88e4e355a39312b7dd1924bdf8fb2c9e38581c92ad3651f91ba5ffd0c385ed172fa4834d0aed3d605e89f3b7bc70
|
7
|
+
data.tar.gz: 31ba0e2502cc5d10ed64ab69ae15864526dd90b698962ba05054f22f1c20d0d518416e0fce86f61980cdc5f3466db9d7dfa1e4f313cec876ea664a1ca4d1306d
|
data/lib/Helper.rb
CHANGED
@@ -113,7 +113,7 @@ class Helper
|
|
113
113
|
result += "author: \"#{postInfo.creator&.gsub("\"", "\\\"")}\"\n"
|
114
114
|
result += "date: #{postInfo.firstPublishedAt.strftime('%Y-%m-%dT%H:%M:%S.%L%z')}\n"
|
115
115
|
result += "last_modified_at: #{postInfo.latestPublishedAt.strftime('%Y-%m-%dT%H:%M:%S.%L%z')}\n"
|
116
|
-
result += "categories: \"#{postInfo.collectionName&.gsub("\"", "\\\"")}\"\n"
|
116
|
+
result += "categories: [\"#{postInfo.collectionName&.gsub("\"", "\\\"")}\"]\n"
|
117
117
|
result += "tags: [#{tags}]\n"
|
118
118
|
result += "description: \"#{postInfo.description&.gsub("\"", "\\\"")}\"\n"
|
119
119
|
if !postInfo.previewImage.nil?
|
data/lib/Post.rb
CHANGED
@@ -51,19 +51,7 @@ class Post
|
|
51
51
|
}
|
52
52
|
]
|
53
53
|
|
54
|
-
|
55
|
-
https = Net::HTTP.new(uri.host, uri.port)
|
56
|
-
https.use_ssl = true
|
57
|
-
request = Net::HTTP::Post.new(uri)
|
58
|
-
request['Content-Type'] = 'application/json'
|
59
|
-
if !$cookie_sid.nil? && !$cookie_uid.nil?
|
60
|
-
request['Cookie'] = "sid=#{$cookie_sid}; uid=#{$cookie_uid}"
|
61
|
-
end
|
62
|
-
request.body = JSON.dump(query)
|
63
|
-
response = https.request(request)
|
64
|
-
|
65
|
-
|
66
|
-
body = Request.body(response)
|
54
|
+
body = Request.body(Request.URL("https://medium.com/_/graphql", method = 'POST', data = query));
|
67
55
|
if !body.nil?
|
68
56
|
json = JSON.parse(body)
|
69
57
|
json&.dig(0, "data", "post", "viewerEdge", "fullContent")
|
data/lib/Request.rb
CHANGED
@@ -22,23 +22,40 @@ class Request
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
raise "Error: Retry limit reached. path: #{url}"
|
31
|
-
else
|
32
|
-
location = response['location']
|
33
|
-
if !location.match? /^(http)/
|
34
|
-
location = "#{uri.scheme}://#{uri.host}#{location}"
|
35
|
-
end
|
36
|
-
|
37
|
-
response = self.URL(location, method, data, retryCount)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
rescue
|
25
|
+
if !$cookie_sid.nil? && !$cookie_uid.nil?
|
26
|
+
request['Cookie'] = "sid=#{$cookie_sid}; uid=#{$cookie_uid}";
|
27
|
+
end
|
28
|
+
|
29
|
+
response = https.request(request);
|
41
30
|
|
31
|
+
cookies = response.get_fields('set-cookie').map { |cookie| cookie.split('; ').first }.each_with_object({}) do |cookie, hash|
|
32
|
+
key, value = cookie.split('=', 2) # Split by '=' into key and value
|
33
|
+
hash[key] = value
|
34
|
+
end;
|
35
|
+
|
36
|
+
if !cookies['uid'].nil?
|
37
|
+
$cookie_uid = cookies['uid'];
|
38
|
+
end
|
39
|
+
|
40
|
+
if !cookies['sid'].nil?
|
41
|
+
$cookie_sid = cookies['sid'];
|
42
|
+
end
|
43
|
+
|
44
|
+
puts response
|
45
|
+
# 3XX Redirect
|
46
|
+
if response.code.to_i == 429
|
47
|
+
raise "Error: Too Manay Reqeust, blocked by Medium.\n####################\n### Please try again later.\n### Ref: https://zhgchg.li/posts/en-medium-to-jekyll/#paywall-posts-require-a-medium-account-with-access-permissions-and-cookies-author-or-medium-member \n####################\n### ERROR URL: #{url}"
|
48
|
+
elsif response.code.to_i >= 300 && response.code.to_i <= 399 && !response['location'].nil? && response['location'] != ''
|
49
|
+
if retryCount >= 10
|
50
|
+
raise "Error: Retry limit reached. path: #{url}"
|
51
|
+
else
|
52
|
+
location = response['location']
|
53
|
+
if !location.match? /^(http)/
|
54
|
+
location = "#{uri.scheme}://#{uri.host}#{location}"
|
55
|
+
end
|
56
|
+
|
57
|
+
response = self.URL(location, method, data, retryCount)
|
58
|
+
end
|
42
59
|
end
|
43
60
|
|
44
61
|
response
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ZMediumToMarkdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ZhgChgLi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|