summaryrefslogtreecommitdiff
path: root/server.rb
diff options
context:
space:
mode:
Diffstat (limited to 'server.rb')
-rw-r--r--server.rb48
1 files changed, 19 insertions, 29 deletions
diff --git a/server.rb b/server.rb
index 6379332..386b519 100644
--- a/server.rb
+++ b/server.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
-before '/inbox' do
+# server-server
+post '/inbox' do
request.body.rewind # in case someone already read it
@body = request.body.read
unless @body.empty?
@@ -9,20 +10,9 @@ before '/inbox' do
@object = fetch(@object) if @object.is_a?(String) && @object.match(/^http/)
halt 400 unless @object
end
-end
-
-# client-server
-post '/outbox' do
- protected!
- # send_signed @activity
-end
-
-# server-server
-post '/inbox' do
verify!
- # file = File.join INBOX, "#{SecureRandom.uuid}.json"
- # File.open(file, 'w+') { |f| f.puts @activity.to_json }
type = @activity['type'].downcase.to_sym
+ p type
respond_to?(type) ? send(type) : p("Unknown activity: #{type}")
end
@@ -32,7 +22,7 @@ get '/.well-known/webfinger' do
send_file('./public/webfinger',
type: 'application/jrd+json')
else
- halt(404)
+ halt 404
end
end
@@ -40,10 +30,10 @@ get '/outbox' do
ordered_collection(OUTBOX).to_json
end
-get '/inbox' do
- # protected!
- ordered_collection(File.join(INBOX, 'note')).to_json
-end
+# get '/inbox' do
+# protected!
+# ordered_collection(File.join(INBOX, 'note')).to_json
+# end
['/following', '/followers'].each do |path|
get path do
@@ -118,6 +108,17 @@ helpers do
create
end
+ def follow
+ File.open(File.join(FOLLOWERS, "#{mention(@activity['actor'])}.json"), 'w+') { |f| f.puts @body }
+ accept = { '@context' => 'https://www.w3.org/ns/activitystreams',
+ 'id' => File.join("#{SOCIAL_URL}#accepts", SecureRandom.uuid),
+ 'type' => 'Accept',
+ 'actor' => ACTOR,
+ 'object' => @activity,
+ 'to' => [@activity['actor']] }
+ send_signed accept
+ end
+
def accept
return unless @object['type'] == 'Follow'
@@ -132,17 +133,6 @@ helpers do
end
end
- def follow
- File.open(File.join(FOLLOWERS, "#{mention(@activity['actor'])}.json"), 'w+') { |f| f.puts @body }
- accept = { '@context' => 'https://www.w3.org/ns/activitystreams',
- 'id' => File.join("#{SOCIAL_URL}#accepts", SecureRandom.uuid),
- 'type' => 'Accept',
- 'actor' => ACTOR,
- 'object' => @activity,
- 'to' => [@activity['actor']] }
- send_signed accept
- end
-
# when "Like"
# when "Move"
# when "Add"