diff options
author | pdp8 <pdp8@pdp8.info> | 2023-07-01 01:54:02 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-07-01 01:54:02 +0200 |
commit | 086709cae3da7a01a011fe906004c8685fdd2ed0 (patch) | |
tree | 0872f3a6cfc303cdc61b883baae47af24960603d /server.rb | |
parent | 5af8d78e195c7479769240b32703d5b76843db4d (diff) |
direct collection access from client
Diffstat (limited to 'server.rb')
-rw-r--r-- | server.rb | 48 |
1 files changed, 19 insertions, 29 deletions
@@ -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" |