summaryrefslogtreecommitdiff
path: root/server.rb
diff options
context:
space:
mode:
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