summaryrefslogtreecommitdiff
path: root/server.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-08-13 10:31:26 +0200
committerpdp8 <pdp8@pdp8.info>2023-08-13 10:31:26 +0200
commit9781dda58c3d2926f928544a8155d493fc2f1ca2 (patch)
tree74d709ee31d90ff02e6c55c7d9ab473e5eff50a2 /server.rb
parent3a8be7b1606885b3b94bc22a6d775a6527e1c07d (diff)
activity/object saving, send activities from file
Diffstat (limited to 'server.rb')
-rw-r--r--server.rb27
1 files changed, 14 insertions, 13 deletions
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