From eea88e8022d3fd3c46401e1a297ebd7318c3c7b1 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Thu, 14 Sep 2023 14:02:15 +0200 Subject: send/digest fixed --- helpers.rb | 72 +++----------------------------------------------------------- 1 file changed, 3 insertions(+), 69 deletions(-) (limited to 'helpers.rb') diff --git a/helpers.rb b/helpers.rb index 26bcd9d..adb0b16 100644 --- a/helpers.rb +++ b/helpers.rb @@ -55,7 +55,7 @@ helpers do end def send_activity(activity, activity_path) - to = [to] if to = activity['to'].is_a?(String) ? [activity['to']] : activity['to'] + to = activity['to'].is_a?(String) ? [activity['to']] : activity['to'] inboxes = [] to.uniq.each do |url| next if [ACTOR, 'https://www.w3.org/ns/activitystreams#Public'].include? url @@ -70,7 +70,7 @@ helpers do end sha256 = OpenSSL::Digest.new('SHA256') - digest = "SHA-256=#{sha256.base64digest(activity)}" + digest = "SHA-256=#{sha256.base64digest(File.read(activity_path))}" keypair = OpenSSL::PKey::RSA.new(File.read('private.pem')) inboxes.compact.uniq.each do |inbox| @@ -98,72 +98,6 @@ helpers do end end - # # add date and id, save - # def save_activity(activity, box) - # date = Time.now.utc.iso8601 - # activity['published'] ||= date # if box == OUTBOX - # basename = "#{activity['published']}_#{mention(activity['actor'])}.json" - # activity_rel_path = File.join(activity['type'].downcase, basename) - # activity_path = File.join(box[:dir], activity_rel_path) - # if box == OUTBOX - # # return unless activity['to'].include? 'https://www.w3.org/ns/activitystreams#Public' # save only public messages - # - # activity['id'] = File.join(box[:url], activity_rel_path) - # activity['object']['published'] = date unless activity['object'].is_a? String - # # save object - # save_object activity['object'], box if %w[Create Announce Update].include? activity['type'] - # end - # # save activity - # FileUtils.mkdir_p File.dirname(activity_path) - # File.open(activity_path, 'w+') { |f| f.puts activity.to_json } - # activity_path - # end - # - # def save_object(object, box) - # object = fetch(object) if object.is_a? String and object.match(/^http/) - # return unless object and object['type'] != 'Person' - # return if box == INBOX and object['id'] and File.readlines(VISITED, chomp: true).include? object['id'] - # - # object['@context'] = 'https://www.w3.org/ns/activitystreams' - # if object['attributedTo'] - # basename = "#{object['published']}_#{mention(object['attributedTo'])}.json" - # else - # basename = "#{object['published']}.json" - # jj object - # end - # object_rel_path = File.join 'object', object['type'].downcase, basename - # object['id'] ||= File.join box[:url], object_rel_path # if box == OUTBOX - # object_path = File.join box[:dir], object_rel_path - # FileUtils.mkdir_p File.dirname(object_path) - # File.open(object_path, 'w+') { |f| f.puts object.to_json } - # if box == OUTBOX and object['tag'] - # object['tag'].each do |tag| - # next unless tag['type'] == 'Hashtag' - # - # tag_path = File.join(TAGS[:dir], tag['name'].sub('#', '')) + '.json' - # tag_collection = if File.exist? tag_path - # JSON.load_file(tag_path) - # else - # { - # '@context' => 'https://www.w3.org/ns/activitystreams', - # 'id' => tag['href'], - # 'type' => 'OrderedCollection', - # 'totalItems' => 0, - # 'orderedItems' => [] - # } - # end - # tag_collection['orderedItems'] << object['id'] - # tag_collection['totalItems'] = tag_collection['orderedItems'].size - # File.open(tag_path, 'w+') do |f| - # f.puts tag_collection.to_json - # end - # end - # elsif box == INBOX - # File.open(File.join(INBOX[:dir], 'visited'), 'a+') { |f| f.puts object['id'] } - # end - # object - # end - def update_collection(path, objects, action = 'add') objects = [objects] unless objects.is_a? Array File.open(path, 'r+') do |f| @@ -209,7 +143,7 @@ helpers do if $CHILD_STATUS.success? response else - p url, response + p 'curl error:', url, response nil end end -- cgit v1.2.3