-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
38 lines (34 loc) · 872 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
38
require 'sinatra'
require "json"
unless File.exist?('./public/booth')
puts 'Create booth:'
puts "run the following command and then rerun the app"
puts 'ln -s ~/Pictures/Photo\ Booth\ Library/Pictures ./public/booth'
exit
end
get '/images' do
images_array = []
images_hash = {}
Dir.foreach("./public/booth") do |element|
images_array << element
end
images_array.delete(".")
images_array.delete("..")
images_hash = {images: images_array}
images_hash.to_json
end
get '/random_images' do
images_array = []
images_hash = {}
Dir.foreach("./public/booth") do |element|
images_array << element
end
images_array.delete(".")
images_array.delete("..")
images_array.shuffle!
images_hash = {images: images_array}
images_hash.to_json
end
get '/' do
File.read(File.join('views', 'index.html')) #send_file '/views/index.html'
end