-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
56 lines (45 loc) · 1.32 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
require "sinatra/base"
require_relative "conda"
require_relative "app"
require "rufus-scheduler"
class CondaAPI < Sinatra::Base
scheduler = Rufus::Scheduler.new
configure :production, :development do
enable :logging
end
get "/" do
"Last updated at #{Conda.instance.channels.values.first.timestamp} \n"
end
get "/packages" do
content_type :json
Conda.instance.packages.to_json
end
get "/package/:name" do
content_type :json
Conda.instance.find_package(params["name"]).to_json
end
get "/package/:name/:version" do
content_type :json
package = Conda.instance.find_package(params["name"]).clone
package[:versions] = package[:versions].select { |version| version[:number] == params["version"] }
package.to_json
end
get "/:channel/" do
content_type :json
Conda.instance.packages_by_channel(params["channel"]).to_json
end
get "/:channel/:name" do
content_type :json
Conda.instance.package(params["channel"], params["name"]).to_json
end
get "/:channel/:name/:version" do
content_type :json
Conda.instance.package_by_channel(params["channel"], params["name"], params["version"]).to_json
end
scheduler.every "15m" do
puts "Reloading packages..."
Conda.instance.reload_all
puts "Reload finished"
end
end