add /kitty route to get a cat picture from CaaS
All checks were successful
Gitea Actions Demo / lint (push) Successful in 19s
Gitea Actions Demo / test (push) Successful in 18s
Gitea Actions Demo / release-image (push) Successful in 2m7s

This commit is contained in:
Ryan Cavicchioni 2025-03-09 20:55:52 -05:00
parent 62f204fa8b
commit 54a3de77e2
Signed by: ryanc
SSH Key Fingerprint: SHA256:KbXiwUnZnHFwFtt3Bytd+F3FN9pPHn1Z1cxMIE1TPbg
3 changed files with 31 additions and 0 deletions

View File

@ -12,6 +12,7 @@ gem "ulid"
gem "uuid7"
gem "jwt"
gem "httparty"
group :development do
gem "ruby-lsp"

View File

@ -4,7 +4,13 @@ GEM
anyflake (0.0.1)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
csv (3.3.0)
diff-lcs (1.6.0)
httparty (0.22.0)
csv
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
json (2.10.1)
jwt (2.10.1)
base64
@ -12,8 +18,11 @@ GEM
language_server-protocol (3.17.0.4)
lint_roller (1.1.0)
logger (1.6.6)
mini_mime (1.1.5)
minitest (5.25.4)
multi_json (1.15.0)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
mustermann (3.0.3)
ruby2_keywords (~> 0.0.1)
nanoid (2.0.0)
@ -118,6 +127,7 @@ PLATFORMS
DEPENDENCIES
anyflake
httparty
jwt
ksuid
minitest

20
app.rb
View File

@ -14,6 +14,8 @@ require "anyflake"
require "jwt"
require "httparty"
$LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
require "config"
@ -495,3 +497,21 @@ get "/bytes/:size" do
generate_bytes(Integer(n))
end
get "/kitty" do
caas_host = ENV.fetch "CAAS_SERVICE_HOST"
caas_port = ENV.fetch "CAAS_SERVICE_PORT"
url = "http://#{caas_host}:#{caas_port}/"
response = HTTParty.head(url)
content_type response.headers["content-type"]
stream do |out|
response = HTTParty.get(url, stream_body: true) do |fragment|
if [301, 302].include? fragment.code
elsif fragment.code == 200
out << fragment
else
raise StandardError, "non-success status code while streaming #{fragment.code}"
end
end
end
end