diff options
author | pdp8 <pdp8@pdp8.info> | 2024-05-03 11:57:42 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2024-05-03 11:57:42 +0200 |
commit | ffade03e9d3f77e41f44882c39eb6b12b3b05e63 (patch) | |
tree | 7cab80e5760996ca74e883d4794992d75a74e8b3 /helpers.rb | |
parent | 97d98fd5481359b96215f8a50d032c8fe96e9add (diff) |
storage paths from id
Diffstat (limited to 'helpers.rb')
-rw-r--r-- | helpers.rb | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -1,6 +1,9 @@ require 'English' helpers do - def save_item(item, path) + def save_item(item, dir) + return unless @object['id'] + + path = File.join(dir, @object['id'].sub('https://', '')) FileUtils.mkdir_p File.dirname(path) File.open(path, 'w+') { |f| f.puts item.to_json } end @@ -10,7 +13,7 @@ helpers do rel_path = File.join(type.downcase, "#{date}.json") activity = { '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => File.join(OUTBOX[:url], rel_path), + 'id' => File.join(OUTBOX_URL, rel_path), 'type' => type, 'actor' => ACTOR, 'published' => date, @@ -22,9 +25,9 @@ helpers do object_rel_path = File.join('object', object['type'].downcase, "#{date}.json") object = activity['object'] object['@context'] = 'https://www.w3.org/ns/activitystreams' - object['id'] = File.join(OUTBOX[:url], object_rel_path) + object['id'] = File.join(OUTBOX_URL, object_rel_path) object['published'] = date - save_item activity['object'], File.join(OUTBOX[:dir], object_rel_path) + save_item activity['object'], OUTBOX_DIR if object['tag'] object['tag'].each do |tag| next unless tag['type'] == 'Hashtag' @@ -49,9 +52,8 @@ helpers do end end end - activity_path = File.join(OUTBOX[:dir], rel_path) - save_item activity, activity_path - send_activity activity, activity_path + save_item activity, OUTBOX_DIR + send_activity activity, File.join(OUTBOX_DIR, rel_path) end def send_activity(activity, activity_path) @@ -209,12 +211,14 @@ 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 - end - 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') |