diff options
-rw-r--r-- | activitypub.rb | 31 | ||||
-rw-r--r-- | public/webfinger (renamed from webfinger) | 0 | ||||
-rw-r--r-- | views/inbox.erb | 50 | ||||
-rw-r--r-- | views/index.erb | 35 |
4 files changed, 57 insertions, 59 deletions
diff --git a/activitypub.rb b/activitypub.rb index ab42c4f..a67c9ba 100644 --- a/activitypub.rb +++ b/activitypub.rb @@ -29,7 +29,7 @@ set :session_secret, File.read(".secret").chomp set :default_content_type, 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' set :port, 9292 -before "/inbox" do +before "/" do if request.request_method == "POST" halt 400 unless verify_signature(request.env) end @@ -123,7 +123,7 @@ end post "/delete/*" do protected! FileUtils.rm params['splat'][0] - redirect to("/inbox") + redirect to("/") end post "/follow/*" do @@ -138,7 +138,7 @@ post "/follow/*" do "object" => actor } send_signed follow, actor File.open(following_path, "w+") { |f| f.puts follow.to_json } - redirect to("/inbox") + redirect to("/") end post "/unfollow/*" do @@ -154,27 +154,40 @@ post "/unfollow/*" do "object" => JSON.parse(File.read(following_path)) } send_signed undo, actor FileUtils.rm following_path - redirect to("/inbox") + redirect to("/") end end post "/login" do session["client"] = true if params["secret"] == File.read(".pwd").chomp - redirect to("/inbox") + redirect to("/") end get "/.well-known/webfinger" do if request["resource"] == "acct:#{ACCOUNT}" - send_file "./webfinger", :type => "application/jrd+json" + send_file "./public/webfinger", :type => "application/jrd+json" else halt 404 end end -get "/inbox", :provides => 'html' do +get "/", :provides => 'html' do protected! - @inbox = Dir['./inbox/*'].sort - erb :inbox + @inbox = Dir['./inbox/*'].sort.collect do |file| + item = JSON.parse(File.read(file)) + mention = mention(item['attributedTo']) + following_path = File.join('public', 'following', mention + '.json') + File.exists?(following_path) ? follow = 'unfollow' : follow = 'follow' + { :file => file, + :actor_url => item['attributedTo'], + :mention => mention, + :follow => follow, + :content => item['content'], + :attachment => item['attachment'] + } + end + p @inbox + erb :index end ["/outbox","/following","/followers"].each do |path| diff --git a/webfinger b/public/webfinger index 507b34e..507b34e 100644 --- a/webfinger +++ b/public/webfinger diff --git a/views/inbox.erb b/views/inbox.erb deleted file mode 100644 index 0be5dd5..0000000 --- a/views/inbox.erb +++ /dev/null @@ -1,50 +0,0 @@ - <!DOCTYPE html> - <html lang='en'> - <head> - <link rel='stylesheet' type='text/css' href='/style.css'> - </head> - <body> - <% @inbox.each_with_index do |file,i| %> - <% item = JSON.parse(File.read(file)) - mention = mention(item['attributedTo']) - following_path = File.join('public', 'following', mention + '.json') %> - <b><a href='<%= item['attributedTo'] %>', target='_blank'><%= mention %></a></b> - <% File.exists?(following_path) ? method = 'unfollow' : method = 'follow' %> - <form action='<%= File.join method, mention %>' method='post'> - <button><%= method.capitalize %></button> - </form> - <p><%= item['content'] %> - <% if item['attachment'] - item['attachment'].each do |att| - case att['mediaType'] - when /audio/ %> - <br><audio controls=''><source src='<%= att['url'] %>' type='<%= att['mediaType'] %>'></audio> - <% when /image/ %> - <br><a href='<%= att['url'] %>'><img src='<%= att['url'] %>'></a> - <% when /video/ %> - <br><video controls=''><source src='<%= att['url'] %>' type='<%= att['mediaType'] %>'></video> - <% else %> - <%= att %><br> - <a href='<%= att['url'] %>'><%= att['url'] %></a> - <% end %> - <% end %> - <% end %> - <p> - <form action='<%= File.join 'delete', file %>' method='post'> - <button>Delete</button> - </form> - <!-- - <form action='<%= File.join 'boost', file %>' method='post'> - <button>Boost</button> - </form> - <form action='<%= File.join 'archive', file %>' method='post'> - <button>Archive</button> - </form> - <form action='<%= File.join 'reply', file %>' method='post'> - <button>Reply</button> - </form> - --> - <hr> - <% end %> - </body> - </html> diff --git a/views/index.erb b/views/index.erb new file mode 100644 index 0000000..a698565 --- /dev/null +++ b/views/index.erb @@ -0,0 +1,35 @@ + <!DOCTYPE html> + <html lang='en'> + <head> + <link rel='stylesheet' type='text/css' href='/style.css'> + </head> + <body> + <% @inbox.each do |item| %> + <b><a href='<%= item[:actor_url] %>', target='_blank'><%= item[:mention] %></a></b> + <form action='<%= File.join item[:follow], item[:mention] %>' method='post'> + <button><%= item[:follow].capitalize %></button> + </form> + <p><%= item[:content] %> + <% if item[:attachment] + item[:attachment].each do |att| + case att['mediaType'] + when /audio/ %> + <br><audio controls=''><source src='<%= att['url'] %>' type='<%= att['mediaType'] %>'></audio> + <% when /image/ %> + <br><a href='<%= att['url'] %>'><img src='<%= att['url'] %>'></a> + <% when /video/ %> + <br><video controls=''><source src='<%= att['url'] %>' type='<%= att['mediaType'] %>'></video> + <% else %> + <%= att %><br> + <a href='<%= att['url'] %>'><%= att['url'] %></a> + <% end %> + <% end %> + <% end %> + <p> + <form action='<%= File.join 'delete', item[:file] %>' method='post'> + <button>Delete</button> + </form> + <hr> + <% end %> + </body> + </html> |