Add route to list available data files
parent
bb61552f20
commit
562451fa5d
11
nikoli.rb
11
nikoli.rb
|
@ -23,9 +23,16 @@ GAMES.each do |game|
|
||||||
get("/#{game}.js") { coffee game }
|
get("/#{game}.js") { coffee game }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/data/:game.json" do |game|
|
||||||
|
data_file = Pathname.new(File.join(settings.data_folder, game))
|
||||||
|
halt(404) unless data_file.directory?
|
||||||
|
|
||||||
|
json data_file.children(false).map { |path| path.to_s.sub(/.yml$/, '') }
|
||||||
|
end
|
||||||
|
|
||||||
get "/data/:game/:file.json" do |game, file|
|
get "/data/:game/:file.json" do |game, file|
|
||||||
data_file = File.join(settings.data_folder, game, "#{file}.yml")
|
data_file = File.expand_path(File.join(settings.data_folder, game, "#{file}.yml"))
|
||||||
halt(404) unless File.exist?(data_file)
|
halt(404) unless File.exist?(data_file)
|
||||||
|
|
||||||
json YAML.load_file(data_file).sample
|
json YAML.load_file(data_file)['data'].sample
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue