From 9781dda58c3d2926f928544a8155d493fc2f1ca2 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Sun, 13 Aug 2023 10:31:26 +0200 Subject: activity/object saving, send activities from file --- server.rb | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'server.rb') diff --git a/server.rb b/server.rb index 4eae86b..4dbfc64 100644 --- a/server.rb +++ b/server.rb @@ -16,7 +16,7 @@ post '/inbox' do type = @activity['type'].downcase.to_sym save_activity(@activity, INBOX) unless %i[create announce].include? type send(type) if %i[create announce follow accept undo].include? type - halt 200 + 200 end # public @@ -88,7 +88,7 @@ helpers do update_collection FOLLOWERS, @activity['object']['actor'], true when 'Create', 'Announce' file = find_file @activity['object']['id'] - FileUtils.rm(file) if File.exist? file + FileUtils.rm(file) if file else halt 501 end @@ -164,15 +164,16 @@ helpers do end # add date and id, save - activity = save_activity({ - '@context' => 'https://www.w3.org/ns/activitystreams', - 'type' => type, - 'actor' => ACTOR, - 'object' => object, - 'to' => to - }, OUTBOX) - - body = activity.to_json + activity_path = save_activity({ + '@context' => 'https://www.w3.org/ns/activitystreams', + 'type' => type, + 'actor' => ACTOR, + 'object' => object, + 'to' => to + }, OUTBOX) + + # p activity_path + body = File.read(activity_path) sha256 = OpenSSL::Digest.new('SHA256') digest = "SHA-256=#{sha256.base64digest(body)}" keypair = OpenSSL::PKey::RSA.new(File.read('private.pem')) @@ -186,9 +187,9 @@ helpers do # Net::HTTP fails with OpenSSL error curl( - "-X POST -H 'Host: #{uri.host}' -H 'Date: #{httpdate}' -H 'Digest: #{digest}' -H 'Signature: #{signed_header}' --data-raw '#{body}'", inbox + "-X POST -H 'Host: #{uri.host}' -H 'Date: #{httpdate}' -H 'Digest: #{digest}' -H 'Signature: #{signed_header}' --data-binary '@#{activity_path}'", inbox ) end - activity + activity_path end end -- cgit v1.2.3