ZMediumToMarkdown 2.4.8 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/Helper.rb +1 -1
  3. data/lib/Post.rb +1 -13
  4. data/lib/Request.rb +33 -16
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f57fec289c42afe9262c5319075daa1062437f57aa63a38bbae9b2b43fd0c875
4
- data.tar.gz: 41a636834bc0f33207ca256269a7ee90d26ac476a3e031b440d374dbc91dfa70
3
+ metadata.gz: 3e2329fa42690e35efea3b0231c03949d460484e821f27b9a3da53fe43908906
4
+ data.tar.gz: 9636ba2e044114cda97780db906014f4bbe7859af23c3236cc79d8928040fffa
5
5
  SHA512:
6
- metadata.gz: 63bbf5dc5e83d105d25716fa9681fa6c3fdd5200ed97eff4b6e31a08c32f0bd107c757bca233992b7b55d3f437312a7c805b063ad68ac2c91fe799571b2f9774
7
- data.tar.gz: 032cd8de78afca0e990ccb328435251224dca318ec5c96b3128165f6c427a76add1bbc99bbff0b6da646782824b68d5734130e5b992a6003aa92d670b1dce662
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
- uri = URI("https://medium.com/_/graphql")
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
- begin
26
- response = https.request(request)
27
- # 3XX Redirect
28
- if response.code.to_i >= 300 && response.code.to_i <= 399 && !response['location'].nil? && response['location'] != ''
29
- if retryCount >= 10
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.8
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-01 00:00:00.000000000 Z
11
+ date: 2025-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri