From ffade03e9d3f77e41f44882c39eb6b12b3b05e63 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Fri, 3 May 2024 11:57:42 +0200 Subject: storage paths from id --- server.rb | 50 +++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'server.rb') diff --git a/server.rb b/server.rb index 9197ce5..b202624 100644 --- a/server.rb +++ b/server.rb @@ -62,7 +62,18 @@ helpers do def create @count ||= 0 @object ||= @activity['object'] - save_inbox_object + @object = @object['object'] if @object['type'] and ACTIVITIES.include? @object['type'].downcase.to_sym # lemmy + return unless @object and @object['type'] != 'Person' + + @object = fetch(@object) if @object.is_a? String and @object.match(/^http/) + return unless @object + + if @object['id'] and File.readlines(VISITED, chomp: true).include? @object['id'] && !(@activity['type'] = 'Update') + return + end + + save_item @object, INBOX_DIR + File.open(VISITED, 'a+') { |f| f.puts @object['id'] } return unless @object and @object['inReplyTo'] and @count < 5 return if File.readlines(VISITED, chomp: true).include?(@object['inReplyTo']) @@ -88,13 +99,13 @@ helpers do end def follow - save_item @activity, File.join(INBOX[:dir], @activity['type'].downcase, activity_name) + # save_item @activity, File.join(INBOX[:dir], @activity['type'].downcase, activity_name) update_collection FOLLOWERS, @activity['actor'] create_activity 'Accept', @activity, [@activity['actor']] end def accept - save_item @activity, File.join(INBOX[:dir], @activity['type'].downcase, activity_name) + # save_item @activity, File.join(INBOX[:dir], @activity['type'].downcase, activity_name) if @activity['object']['type'] == 'Follow' update_collection FOLLOWING, @activity['object']['object'] else @@ -109,8 +120,9 @@ helpers do when 'Follow' update_collection FOLLOWERS, @activity['object']['actor'], 'delete' when 'Create', 'Announce' - file, object = find_object @activity['object']['object'] - FileUtils.rm(file) if file and File.exist? file and @activity['actor'] == object['attributedTo'] + file = File.join(dir, @activity['object']['id'].sub('https://', '')) + # file, object = find_object @activity['object']['object'] + FileUtils.rm(file) if file and File.exist? file # and @activity['actor'] == object['attributedTo'] else p "Error: Cannot undo @activity['object']['type']" jj @activity @@ -124,8 +136,9 @@ helpers do end def delete - file, object = find_object(@activity['object']['id']) - FileUtils.rm(file) if file and File.exist? file and @activity['actor'] == object['attributedTo'] + file = File.join(dir, @activity['object']['id'].sub('https://', '')) + # file, object = find_object(@activity['object']['id']) + FileUtils.rm(file) if file and File.exist? file # and @activity['actor'] == @activity['object']['attributedTo'] end def move @@ -134,7 +147,7 @@ helpers do def handle_activity type = @activity['type'].downcase.to_sym - save_item @activity, File.join(INBOX[:dir], @activity['type'].downcase, activity_name) + # save_item @activity, File.join(INBOX[:dir], @activity['type'].downcase, activity_name) if ACTIVITIES.include? type send(type) else @@ -149,27 +162,6 @@ helpers do @activity['published'] ? "#{@activity['published']}_#{mention(@activity['actor'])}.json" : "#{Time.now.utc.iso8601}_#{mention(@activity['actor'])}.json" end - def save_inbox_object - @object = @object['object'] if @object['type'] and ACTIVITIES.include? @object['type'].downcase.to_sym # lemmy - return unless @object and @object['type'] != 'Person' - - @object = fetch(@object) if @object.is_a? String and @object.match(/^http/) - return unless @object - - # if @activity['type'] != 'Update' && (@object['id'] and File.readlines(VISITED, chomp: true).include? @object['id']) - # return - # end - if @object['id'] and File.readlines(VISITED, chomp: true).include? @object['id'] && !(@activity['type'] = 'Update') - return - # - # FileUtils.rm_f find_object(@object['id'])[0] - # - end - - save_item @object, File.join(INBOX[:dir], 'object', @object['type'].downcase, activity_name) - File.open(VISITED, 'a+') { |f| f.puts @object['id'] } - end - def outbox(activity) Dir[File.join('outbox', activity, '*.json')].collect do |f| JSON.load_file(f) -- cgit v1.2.3