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
version: 1.5.0
pool:
git: https://github.com/ysbaddaden/pool.git
version: 0.2.4
radix:
git: https://github.com/luislavena/radix.git
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:
kemal:
github: kemalcr/kemal
redis:
github: stefanwille/crystal-redis
# authors:

View file

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

View file

@ -9,6 +9,9 @@ class Config
property gqlClientID : String?
property apiEndpoint : String?
property gqlEndpoint : String?
property redis_url : String?
property redis_socket : String?
property port : Int32 = 8080
def self.load
config_file = "config/config.yml"
@ -25,16 +28,6 @@ class Config
exit(1)
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
end
end

View file

@ -5,10 +5,14 @@ require "uri"
require "./config"
require "./api/*"
require "./twitchapi/*"
require "redis"
CONFIG = Config.load
# puts("helixOAuth: #{CONFIG.helixOAuth}")
# puts("helixClientID: #{CONFIG.helixClientID}")
Kemal.config.port = CONFIG.port
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|
env.response.content_type = "application/json"
@ -46,4 +50,8 @@ get "/twitch/user" do |env|
end
end
{% if flag?(:release) || flag?(:production) %}
Kemal.config.env = "production" if !ENV.has_key?("KEMAL_ENV")
{% end %}
Kemal.run

View file

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