forked from mleone/broadcast
-
Notifications
You must be signed in to change notification settings - Fork 1
/
broadcast.rb
56 lines (46 loc) · 1.26 KB
/
broadcast.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
require "erb"
require "json/pure"
require "android_interface"
require "file_tree_interface"
class Broadcast < Sinatra::Base
include AndroidInterface
include FileTreeInterface
set :views, VIEW_DIR
set :public, PUBLIC_DIR
get '/' do
@latitude, @longitude = location_coordinates
@temp = battery_temperature
@status = battery_status
erb :"index.html"
end
# This takes a POST request for jquery-file-tree compatability,
# I don't necessarily agree with it
post '/browse' do
render_file_tree params[:dir]
end
get "/download" do
f = File.join MEDIA_DIR + params[:file]
send_file f, :disposition => 'attachment', :filename => File.basename(f)
end
get "/snapshot.jpg" do
content_type 'image/png'
capture_picture_data
end
get "/update.jpg" do
content_type 'image/png'
capture_picture_data :refresh => true
end
get '/location.json' do
content_type 'json'
location_coordinates(:refresh => true).to_json
end
post '/say.json' do
content_type 'json'
say(params[:message]).to_json
end
# using PUT request instead of POST, prevents problems uploading large files.
put '/upload' do
content_type 'json'
save_upload(params["qqfile"], env["rack.request.form_vars"]).to_json
end
end