jekyll-hackclub 1.5.1 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 946c0c6e84743e07d73f28be93196ab5b36f64aac96b6b38c874f2f312b64bcd
4
- data.tar.gz: e1042a102d08ca8591bfd7ea152d1ff5b3603257372c301bd94d9d224e834417
3
+ metadata.gz: c35199cb176d936872986c6dbb7b46e65cb6b11f21250f759099b143cb8bb378
4
+ data.tar.gz: bdd6a99a115b5b9b6c1c0e45c6e97477abac61476e73c61513fd590945cab7b4
5
5
  SHA512:
6
- metadata.gz: c93c3636b08e11618087f9927dee95e724721b7ff2675e7868c6da030a863a0e8bff1c9803d1cc8ac0d16bb93c85228c80bf30ea3ac41f74ccf3c0cbdd6ac2c0
7
- data.tar.gz: d44840b14ac1712cb1d1469287d3e6b9a64984c4ef22731654dfae51ea806330c7ef0fa535b5559af236cba1c6e8f162a5dfdeccc8e2da925037129074189171
6
+ metadata.gz: 96e1e7198747743df95612dec2bd2c944dd82d62bb7ce8d05886515d49c217cd362d9b55f522707d9a9269011d607b39e3a95ad3b883fa4dbf39c51723304c09
7
+ data.tar.gz: 79da52c88ea5cb8b3f299b513ec44a74cc4bbe667b522523a464acbbb3e72b88c695786b3da402256277de2916435f814d3ee22a9f4c1342e6d7ab59589a91c2
data/lib/server-bridge.rb CHANGED
@@ -3,34 +3,60 @@ require "json"
3
3
  require "uri"
4
4
 
5
5
  module HackclubRequest
6
- DEFAULT_EMOJI = "https://emoji.slack-edge.com/T0266FRGM/alibaba-question/c5ba32ce553206b8.png" # :alibaba-question:
6
+ DEFAULT_EMOJI = "https://cdn.hackclub.com/019ce841-fe66-72e6-bb16-d57a93ac574f/alibaba-question.png" # :alibaba-question:
7
7
  @host = Jekyll.configuration({})['HACKCLUB_API'] || "https://hackclub.mathiasd.fr"
8
+ DEFAULT_RETRIES = 3
9
+ RETRYABLE_STATUS_CODES = [408, 425, 429, 500, 502, 503, 504].freeze
8
10
 
9
11
  class << self
10
12
  attr_accessor :host
11
13
  end
12
14
 
13
- def self.make_request(path)
15
+ def self.make_request(path, retries: DEFAULT_RETRIES, base_delay: 0.25)
14
16
  uri = URI("#{host}#{path}")
15
- req = Net::HTTP::Get.new(uri)
16
- req['Referer'] = "jekyll-hackclub"
17
+ attempts = 0
17
18
 
18
- res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
19
- http.request(req)
19
+ while attempts < retries
20
+ attempts += 1
21
+
22
+ begin
23
+ req = Net::HTTP::Get.new(uri)
24
+ req['Referer'] = "jekyll-hackclub"
25
+
26
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https", open_timeout: 3, read_timeout: 6) do |http|
27
+ http.request(req)
28
+ end
29
+
30
+ if RETRYABLE_STATUS_CODES.include?(res.code.to_i)
31
+ sleep(base_delay * attempts) if attempts < retries
32
+ next
33
+ end
34
+
35
+ return JSON.parse(res.body), res
36
+ rescue JSON::ParserError
37
+ return {}, res
38
+ rescue => e
39
+ if attempts < retries
40
+ sleep(base_delay * attempts)
41
+ next
42
+ end
43
+
44
+ warn "Request to #{uri} failed after #{attempts} attempts: #{e}"
45
+ return {}, nil
46
+ end
20
47
  end
21
48
 
22
- return JSON.parse(res.body), res
23
- rescue JSON::ParserError
24
- return {}, res
25
- rescue => e
26
- warn "Request to #{uri} failed: #{e}"
27
49
  return {}, nil
28
50
  end
29
51
 
30
- def self.get_emoji(id)
52
+ def self.get_emoji_url(id)
31
53
  return "#{host}/emoji/#{id.strip}"
32
54
  end
33
55
 
56
+ def self.get_pfp_url(id, quality)
57
+ return "#{host}/profile.picture/#{id.strip}?q=#{quality}"
58
+ end
59
+
34
60
  def self.raw_file(fileid)
35
61
  data, res = make_request("/files.info/#{fileid}")
36
62
  res&.is_a?(Net::HTTPSuccess) ? data : {}
data/lib/tags/emoji.rb CHANGED
@@ -6,7 +6,7 @@ module Jekyll
6
6
  def initialize(tagName, content, tokens)
7
7
  super
8
8
  @id = content.gsub(/\A:+|:+\z/, '').strip
9
- @img_url = HackclubRequest.get_emoji(@id)
9
+ @img_url = HackclubRequest.get_emoji_url(@id)
10
10
  end
11
11
 
12
12
  def render(context)
@@ -10,15 +10,14 @@ module Jekyll
10
10
  data = HackclubRequest.raw_user(id)
11
11
  @resolution = Regexp.last_match(2) || "original"
12
12
 
13
- @img_url = data.dig("user", "profile", "image_"+@resolution)
14
- @name = data.dig("user", "name")
13
+ @img_url = HackclubRequest.get_pfp_url(id, @resolution)
15
14
  else
16
15
  raise ArgumentError, "Invalid profilepic tag format: #{content}"
17
16
  end
18
17
  end
19
18
 
20
19
  def render(context)
21
- %Q{<img src="#{@img_url}" title="#{@name}'s profile picture" alt="#{@name}'s profile picture" class="hackclub-pfp res-#{@resolution}">}
20
+ %Q{<img src="#{@img_url}" title="Slack profile picture" alt="Slack profile picture" class="hackclub-pfp res-#{@resolution}">}
22
21
  end
23
22
  end
24
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-hackclub
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - MathiasDPX