write CaaS cat as a temporary file
All checks were successful
Gitea Actions Demo / lint (push) Successful in 26s
Gitea Actions Demo / test (push) Successful in 14s
Gitea Actions Demo / release-image (push) Successful in 1m57s

this will make it eaiser to set the content-type correctly
This commit is contained in:
Ryan Cavicchioni 2025-03-10 14:55:31 -05:00
parent 54a3de77e2
commit b247971b7e
Signed by: ryanc
SSH Key Fingerprint: SHA256:FEbwJ3JyWHwYNAM8BqctZ/LmHHg1bzfi/huOj7FxlXU

21
app.rb
View File

@ -499,19 +499,28 @@ get "/bytes/:size" do
end
get "/kitty" do
caas_host = ENV.fetch "CAAS_SERVICE_HOST"
caas_port = ENV.fetch "CAAS_SERVICE_PORT"
caas_host = ENV.fetch "CAAS_SERVICE_HOST", nil
caas_port = ENV.fetch "CAAS_SERVICE_PORT", nil
url = "http://#{caas_host}:#{caas_port}/"
response = HTTParty.head(url)
content_type response.headers["content-type"]
stream do |out|
unless caas_host && caas_port
# fail-safe url
url = "https://i.imgur.com/epzPw7L.jpeg"
end
path = Tempfile.open binmode: true do |f|
# f.chmod 0o644
response = HTTParty.get(url, stream_body: true) do |fragment|
if [301, 302].include? fragment.code
print "skip writing for redirect"
elsif fragment.code == 200
out << fragment
f.write fragment
else
raise StandardError, "non-success status code while streaming #{fragment.code}"
end
end
content_type response.headers["content-type"]
f.path
end
send_file path
File.delete path
end