-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoffline.ru
55 lines (49 loc) · 1.27 KB
/
offline.ru
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
#!/usr/bin/env ruby
require 'net/http'
require 'json'
meta = JSON.parse(File.read('offline/meta.json'))
data = JSON.parse(File.read('offline/data.json'))
app = proc do |ev|
ret = ""
options = {}
req_path = ev['REQUEST_PATH'].split('/')
options[:user] = req_path[1]
options[:repo] = req_path[2]
options[:page] = req_path[3]
case options[:page]
when 'network_meta'
ret = meta.to_json
typ = 'text/json'
when 'network_data_chunk'
start, finish = 558, 758
query = {}
ev['QUERY_STRING'].split('&').each do |arg|
args = arg.split('=')
query[args[0]] = args[1]
end
if (query['start'] && query['end'])
start, finish = query['start'].to_i, query['end'].to_i
end
gen = {}
gen['commits'] = data['commits'][start..finish]
ret = gen.to_json
typ = 'text/json'
when 'network.js'
ret = File.read('network.js')
typ = 'text/javascript'
when 'network'
ret = File.read('index.html')
typ = 'text/html'
when 'jquery-1.3.2.min.js'
ret = File.read('jquery-1.3.2.min.js')
type = 'text/javascript'
else
nil
end
return [ 200,
{'Content-Type' => typ,
'Content-Length' => ret.length.to_s},
[ret] ]
end
use Rack::CommonLogger
run app