-
Notifications
You must be signed in to change notification settings - Fork 0
/
final.rb
executable file
·52 lines (43 loc) · 1.29 KB
/
final.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
require "rubygems"
require "sinatra"
require "aws/s3"
before do
AWS::S3::Base.establish_connection!(
:access_key_id => 'AKIAJ6AECJ44RP4N2ICA',
:secret_access_key => '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'
)
end
get "/" do
# List all buckets here
@buckets = AWS::S3::Service.buckets
erb :index
end
get "/buckets/:name" do
# Find bucket with :name, and list all files
@bucket = AWS::S3::Bucket.find(params[:name])
erb :buckets_index
end
post "/buckets/:name" do
# Upload file to bucket with :name
filename = params[:file][:filename] + ".htm"
system "abiword --verbose=0 --to=" << filename << " " << params[:file][:tempfile].path
file =File.open(filename,"r")
AWS::S3::S3Object.store( filename, file, params[:name] )
system "rm "<<filename
system "rm -r "<< filename << "_files"
redirect "/buckets/#{params[:name]}"
end
get "/buckets/:name/new" do
# Find bucket with :name, and render a form (form provided in sample)
@bucket = AWS::S3::Bucket.find(params[:name])
erb :buckets_new
end
post '/edit/save/:name' do
AWS::S3::S3Object.store( params[:name], params[:content], 'waynelin_hw3')
redirect "/edit/#{params[:name]}"
end
get "/edit/:name" do
@filename = params[:name]
@file = AWS::S3::S3Object.value params[:name],'waynelin_hw3'
erb :edit
end