summaryrefslogtreecommitdiff
path: root/server.rb
diff options
context:
space:
mode:
Diffstat (limited to 'server.rb')
-rw-r--r--server.rb55
1 files changed, 16 insertions, 39 deletions
diff --git a/server.rb b/server.rb
index 386b519..11b6411 100644
--- a/server.rb
+++ b/server.rb
@@ -4,21 +4,26 @@
post '/inbox' do
request.body.rewind # in case someone already read it
@body = request.body.read
- unless @body.empty?
+ halt 400 if @body.empty?
+ begin
@activity = JSON.parse @body
- @object = @activity['object']
- @object = fetch(@object) if @object.is_a?(String) && @object.match(/^http/)
- halt 400 unless @object
+ rescue StandardError
+ p @body
+ halt 400
end
- verify!
type = @activity['type'].downcase.to_sym
p type
- respond_to?(type) ? send(type) : p("Unknown activity: #{type}")
+ halt 501 unless respond_to?(type)
+ @object = @activity['object']
+ @object = fetch(@object) if @object.is_a?(String) && @object.match(/^http/)
+ halt 400 unless @object
+ verify!
+ send(type)
end
# public
get '/.well-known/webfinger' do
- if request['resource'] == "acct:#{ACCOUNT}"
+ if request['resource'] == "acct:#{MENTION}"
send_file('./public/webfinger',
type: 'application/jrd+json')
else
@@ -27,14 +32,9 @@ get '/.well-known/webfinger' do
end
get '/outbox' do
- ordered_collection(OUTBOX).to_json
+ ordered_collection(OUTBOX_DIR).to_json
end
-# get '/inbox' do
-# protected!
-# ordered_collection(File.join(INBOX, 'note')).to_json
-# end
-
['/following', '/followers'].each do |path|
get path do
ordered_collection(File.join(PUBLIC_DIR, path)).to_json
@@ -93,36 +93,19 @@ helpers do
create if @object
end
- def delete
- Dir['inbox/*/*.json'].each do |file|
- FileUtils.rm file if JSON.parse(File.read(file))['id'] == @object['id']
- end
- end
-
- def update
- delete
- create
- end
-
def announce
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
+ outbox 'Accept', @activity, [@activity['actor']]
end
def accept
return unless @object['type'] == 'Follow'
- File.open(File.join(FOLLOWING, "#{mention(@object['object'])}.json"), 'w+') { |f| f.puts @object.to_json }
+ File.open(File.join(FOLLOWING_DIR, "#{mention(@object['object'])}.json"), 'w+') { |f| f.puts @object.to_json }
end
def undo
@@ -133,14 +116,8 @@ helpers do
end
end
- # when "Like"
- # when "Move"
- # when "Add"
- # when "Remove"
- # when "Block"
-
def inbox
- Dir[File.join(INBOX, '*', '*.json')].collect do |file|
+ Dir[File.join(INBOX_DIR, 'note', '*.json')].collect do |file|
JSON.parse(File.read(file))
end.sort_by { |o| o['published'] }
end