Class: MainController
Constant Summary
collapse
- AUTH_IMG_EXT =
%w(.jpg .jpeg .png .gif)
Instance Attribute Summary
#callpath, #env, #infos, #params
Instance Method Summary
collapse
#initialize
Instance Method Details
#add_url ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'app/main.rb', line 13
def add_url
url = arguments["url"]
if url
Dataset << url
return {plain: "#{url} added"}
else
return {plain: "url argument required"}
end
end
|
#debug ⇒ Object
51
52
53
|
# File 'app/main.rb', line 51
def debug
binding.pry
end
|
#hello ⇒ Object
33
34
35
|
# File 'app/main.rb', line 33
def hello
{html: "<html><body><h1>hello world</h1><p>lol</p></body></html>"}
end
|
#image ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'app/main.rb', line 38
def image
dir = File.expand_path('controllers/')
file = File.expand_path(params["image"], dir)
if not file[0..(dir.size-1)] == dir or not AUTH_IMG_EXT.include?(File.extname(file))
return {status: 500, content: "invalid path #{params['image']}"}
elsif not File.exists? file
return {status: 404, content: "invalid path #{params['image']}"}
else
return {type: 'image/jpeg', content: File.read(file)}
end
end
|
#rm_url ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'app/main.rb', line 23
def rm_url
url = arguments[:url]
if url
Dataset.rm url
return {plain: "#{url} removed"}
else
return {plain: "url argument required"}
end
end
|
#root ⇒ Object
3
4
5
6
7
8
9
10
11
|
# File 'app/main.rb', line 3
def root
{
json: {
list: $dataset,
add: '/add',
rm: '/rm',
}
}
end
|