predator_pics/server.rb

29 lines
550 B
Ruby
Raw Normal View History

2024-11-10 13:12:42 +00:00
require 'json'
require 'faraday'
require 'sinatra'
require_relative 'get_images_by_category.rb'
require_relative 'get_random_image.rb'
categories = File.readlines("categories.txt")
get '/' do
image = get_random_image(get_images_by_category(categories))
erb :index, locals: { image: image }
end
get '/about' do
erb :about
2024-11-10 17:13:42 +00:00
end
get '/api/random' do
content_type :json
image = get_random_image(get_images_by_category(categories))
image.to_json
end
get '/api/categories' do
content_type :json
categories.to_json
2024-11-10 13:12:42 +00:00
end