From 44967ae9f605ca37b6d88e4e8b11a9cf1fdc2b57 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Thu, 14 Sep 2023 20:20:26 +0200 Subject: note objects fixed, verify reactivated --- create.rb | 10 ++++++++-- helpers.rb | 14 +++----------- server.rb | 2 +- views/outbox.erb | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 views/outbox.erb diff --git a/create.rb b/create.rb index 8e221c8..40e1357 100644 --- a/create.rb +++ b/create.rb @@ -4,6 +4,7 @@ ATTACH_REGEXP = /^attach:\s+/i URL_REGEXP = %r{\Ahttps?://\S+\Z} MENTION_REGEXP = /\A@\w+@\S+\Z/ HASHTAG_REGEXP = /\A#\w+\Z/ +# COMMENT_REGEXP = /^$/ + next when TO_REGEXP line.sub(TO_REGEXP, '').split(/\s+/).each do |word| case word @@ -71,9 +76,10 @@ post '/create' do object['inReplyTo'] = inReplyTo unless inReplyTo.empty? object['attachment'] = attachment unless attachment.empty? object['tag'] = tag unless tag.empty? - jj object + # p to + # jj object - # create_activity 'Create', object, to + create_activity 'Create', object, to 200 end diff --git a/helpers.rb b/helpers.rb index 89ce7d4..536a7c6 100644 --- a/helpers.rb +++ b/helpers.rb @@ -17,8 +17,6 @@ helpers do 'to' => to, 'object' => object } - activity_path = File.join(OUTBOX[:dir], rel_path) - save_item activity, activity_path unless activity['object'].is_a? String object_rel_path = File.join('object', object['type'].downcase, "#{date}.json") @@ -51,6 +49,8 @@ helpers do end end end + activity_path = File.join(OUTBOX[:dir], rel_path) + save_item activity, activity_path send_activity activity, activity_path end @@ -80,6 +80,7 @@ helpers do signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest.new('SHA256'), string)) signed_header = "keyId=\"#{ACTOR}#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) host date digest content-type\",signature=\"#{signature}\"" + p inbox # Net::HTTP fails with OpenSSL error curl( "-X POST -H 'Host: #{uri.host}' -H 'Date: #{httpdate}' -H 'Digest: #{digest}' -H 'Signature: #{signed_header}' --data-binary '@#{activity_path}'", inbox @@ -207,13 +208,4 @@ helpers do JSON.load_file(f)['id'] == id end end - - # def find_id(id, return_filename = true) - # Dir[File.join('**', '*.json')].find do |f| - # content = JSON.load_file(f) - # if content['id'] == id - # return_filename ? f : content - # end - # end - # end end diff --git a/server.rb b/server.rb index b0f3bd9..0807375 100644 --- a/server.rb +++ b/server.rb @@ -10,7 +10,7 @@ post '/inbox' do end # deleted actors return 403 => verification error halt 200 if @activity['type'] == 'Delete' and @activity['actor'] == @activity['object'] - # verify! # pixelfed sends unsigned activities??? + verify! # pixelfed sends unsigned activities??? handle_activity 200 end diff --git a/views/outbox.erb b/views/outbox.erb new file mode 100644 index 0000000..db840f4 --- /dev/null +++ b/views/outbox.erb @@ -0,0 +1,41 @@ + + + + + pdp8 social + + + + +

pdp8@social.pdp8.info

+ music, pictures and videos: https://pdp8.info + <% @activities.each do |activity| + file = find_file activity['object']['id'] + @object = JSON.load_file file if file and File.exists? file + if @object + mention = mention @object['attributedTo'] %> +
+

' target='_blank'><%= mention %>  + <%= @object['published'] %> + <% if activity['type'] == 'Announce' %> +  (announced) + <% end %> +

+ <%= @object['content']%> + <% if @object['attachment'] + @object['attachment'].each do |att| + case att['mediaType'] + when /audio/ %> +
+ <% when /image/ %> +
'>' alt='<%= att['name'].gsub("'",''').gsub('"','"') if att['name'] %>'> + <% when /video/ %> +
+ <% end %> + <% end %> + <% end %> +

+ <% end %> + <% end %> + + -- cgit v1.2.3