fuck ryanpotat

This commit is contained in:
Fijxu 2024-05-19 03:50:02 -04:00
parent 00640f3ab6
commit ec3df79f6e
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
7 changed files with 81 additions and 30 deletions

16
README.md Normal file
View file

@ -0,0 +1,16 @@
### TODO
- Use Redis to cache replies and add a new key to report for how much time the JSON is going to be stored in cache (**Already started, but I need to fix it!!**)
- Add other endpoints from api.ivr.fi
- CAPTURE MORE THAN 1 PARAM `?login=fuck,fuck`
### NOT SO IMPORTANT TODO
- Rate limiting (can be done in the reverse proxy side)
- Better shitcode
- STOP USING KEMAL FOR SIMPLE THINGS!
### Suggestions
3:45 RyanPotat: add team

View file

@ -12,7 +12,15 @@ shards:
git: https://github.com/kemalcr/kemal.git git: https://github.com/kemalcr/kemal.git
version: 1.5.0 version: 1.5.0
pool:
git: https://github.com/ysbaddaden/pool.git
version: 0.2.4
radix: radix:
git: https://github.com/luislavena/radix.git git: https://github.com/luislavena/radix.git
version: 0.4.1 version: 0.4.1
redis:
git: https://github.com/stefanwille/crystal-redis.git
version: 2.9.1

View file

@ -8,6 +8,8 @@ targets:
dependencies: dependencies:
kemal: kemal:
github: kemalcr/kemal github: kemalcr/kemal
redis:
github: stefanwille/crystal-redis
# authors: # authors:

View file

@ -17,9 +17,9 @@ module Users
def self.checkBanned(gql) def self.checkBanned(gql)
# puts "checkBanned: #{gql}" # puts "checkBanned: #{gql}"
# puts (typeof(gql)) # puts (typeof(gql))
# if gql["userResultByLogin"] # if gql["userResultByLogin"]
# return false # return false
# if gql["userResultByLogin"]["result"]? # if gql["userResultByLogin"]["result"]?
# return true # return true
# else # else
# return false # return false
@ -42,17 +42,17 @@ module Users
# return false # return false
# end # end
# return false # return false
if GqlAPI.urb().includes? "login" if GqlAPI.urb.includes? "login"
if gql["userResultByLogin"]["reason"]? if gql["userResultByLogin"]["reason"]?
return true return gql["userResultByLogin"]["reason"]
else else
return false return nil
end end
elsif GqlAPI.urb().includes? "id" elsif GqlAPI.urb.includes? "id"
if gql["userResultByID"]["reason"]? if gql["userResultByID"]["reason"]?
return true return gql["userResultByID"]["reason"]
else else
return false return nil
end end
end end
end end
@ -80,18 +80,38 @@ module Users
# spawn do # spawn do
# a.send fetchGQL(id.to_s) # a.send fetchGQL(id.to_s)
# end # end
login = params["login"]?
id = params["id"]?
if login && (json = REDIS_DB.get(login))
puts (JSON.parse(json))
return json
elsif id && (json = REDIS_DB.get(id))
return json
end
# puts REDIS_DB.get(params["login"]?)
# puts REDIS_DB.get(params["id"]?)
# if (json = (REDIS_DB.get(params["login"]?.to_s))) || (json = (REDIS_DB.get(params["id"]?.to_s)))
# if ((json = REDIS_DB.get(id))
# puts json
# return json
# end
gql = GqlAPI.query(params) gql = GqlAPI.query(params)
panels = gql["user"]["panels"] panels = gql["user"]["panels"]
banned = checkBanned(gql) banned = checkBanned(gql)
# puts banned # puts(banned)
# puts ("urb #{GqlAPI.urb()}")
# pp gql
json_data = [ json_data = [
{ {
"banned" => banned, "cache" => {
"reason" => nil, "isCached" => false,
"expireTime" => nil : Int32,
},
"banned" => false,
"reason" => banned,
"displayName" => gql["user"]["displayName"], "displayName" => gql["user"]["displayName"],
"login" => gql["user"]["login"], "login" => gql["user"]["login"],
"id" => gql["user"]["id"], "id" => gql["user"]["id"],
@ -121,11 +141,15 @@ module Users
"panels" => panels, "panels" => panels,
}, },
] ]
if banned != nil
json_data[0]["banned"] = true
end
# if json_data[0]["banned"].nil? if id
# puts "test" REDIS_DB.set(id, json_data.to_json, ex: 5)
# json_data[0]["reason"] = gql["userResultByID"]["reason"] else
# end REDIS_DB.set(login.to_s, json_data.to_json, ex: 5)
end
return json_data.to_json return json_data.to_json
end end

View file

@ -9,6 +9,9 @@ class Config
property gqlClientID : String? property gqlClientID : String?
property apiEndpoint : String? property apiEndpoint : String?
property gqlEndpoint : String? property gqlEndpoint : String?
property redis_url : String?
property redis_socket : String?
property port : Int32 = 8080
def self.load def self.load
config_file = "config/config.yml" config_file = "config/config.yml"
@ -25,16 +28,6 @@ class Config
exit(1) exit(1)
end end
if config.apiEndpoint.to_s.empty?
puts "Config: 'apiEndpoint' is required/can't be empty"
exit(1)
end
if config.gqlEndpoint.to_s.empty?
puts "Config: 'apiEndpoint' is required/can't be empty"
exit(1)
end
return config return config
end end
end end

View file

@ -5,10 +5,14 @@ require "uri"
require "./config" require "./config"
require "./api/*" require "./api/*"
require "./twitchapi/*" require "./twitchapi/*"
require "redis"
CONFIG = Config.load CONFIG = Config.load
# puts("helixOAuth: #{CONFIG.helixOAuth}") Kemal.config.port = CONFIG.port
# puts("helixClientID: #{CONFIG.helixClientID}") REDIS_DB = Redis::PooledClient.new(unixsocket: CONFIG.redis_socket || nil, url: CONFIG.redis_url || nil)
if REDIS_DB.ping
puts "Connected to redis"
end
before_all "/twitch/*" do |env| before_all "/twitch/*" do |env|
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -46,4 +50,8 @@ get "/twitch/user" do |env|
end end
end end
{% if flag?(:release) || flag?(:production) %}
Kemal.config.env = "production" if !ENV.has_key?("KEMAL_ENV")
{% end %}
Kemal.run Kemal.run

View file

@ -14,7 +14,7 @@ module HelixAPI
response = HTTP::Client.get(endpoint, headers: @@headers) response = HTTP::Client.get(endpoint, headers: @@headers)
puts response.body # puts response.body
if response.success? if response.success?
return (response.body) return (response.body)
else else