-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.rb
37 lines (31 loc) · 846 Bytes
/
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
require 'sinatra'
require_relative 'calibre.rb'
require_relative 'logos.rb'
## setup
bookdir = ARGV[0]
raise "Please specify a Calibre library directory as a parameter when running this server" if bookdir.nil?
CalibreBook.connect(bookdir)
books = CalibreBook.some_books(15)
## endpoints
get '/' do
@books = CalibreBook.some_books(25)
erb :index
end
get '/author/:query' do
@books = CalibreBook.search_author params['query']
erb :index
end
get '/series/:query' do
@books = CalibreBook.search_series params['query']
erb :index
end
get '/download/*' do
filepath = "/" + params['splat'].first
filepath.gsub!("/../","/") # try to avoid exposing the whole filesystem, probably not good enough
puts "DEBUG getting #{filepath}"
if filepath.start_with? bookdir
send_file filepath
else
raise Sinatra::NotFound
end
end