From a9b6e7f9011bbf006fb86d1974b9b8ce8293c6b8 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Sun, 14 Jul 2024 23:21:15 +0200 Subject: outbox formatting --- helpers.rb | 33 ++++++++++++++++----------------- server.rb | 8 ++++---- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/helpers.rb b/helpers.rb index c2b0136..72666b1 100644 --- a/helpers.rb +++ b/helpers.rb @@ -1,9 +1,17 @@ require 'English' helpers do - def save_item(item, dir) - return unless @object['id'] + def save_inbox(item) + return unless item['id'] - path = File.join(dir, @object['id'].sub('https://', '')) + path = File.join(INBOX_DIR, item['id'].sub('https://', '')) + FileUtils.mkdir_p File.dirname(path) + File.open(path, 'w+') { |f| f.puts item.to_json } + end + + def save_outbox(item) + return unless item['id'] + + path = item['id'].sub(SOCIAL_URL, SOCIAL_DIR) FileUtils.mkdir_p File.dirname(path) File.open(path, 'w+') { |f| f.puts item.to_json } end @@ -27,7 +35,7 @@ helpers do object['@context'] = 'https://www.w3.org/ns/activitystreams' object['id'] = File.join(OUTBOX_URL, object_rel_path) object['published'] = date - save_item activity['object'], OUTBOX_DIR + save_outbox activity['object'] if object['tag'] object['tag'].each do |tag| next unless tag['type'] == 'Hashtag' @@ -52,7 +60,7 @@ helpers do end end end - save_item activity, OUTBOX_DIR + save_outbox activity send_activity activity, File.join(OUTBOX_DIR, rel_path) end @@ -211,15 +219,6 @@ helpers do "#{type[0]}/#{ext}" end - # def find_object(id) - # Dir[File.join('*', '**', '*.json')].each do |file| - # object = JSON.load_file(file) - # return [file, object] if object['id'] == id - # rescue JSON::ParserError - # puts "Invalid JSON in #{file}" - # end - # end - def outbox_html(activity) html = File.read('/home/ch/src/publish/html/head.html') html += '