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 /server.rb | |
parent | 97d98fd5481359b96215f8a50d032c8fe96e9add (diff) |
storage paths from id
Diffstat (limited to 'server.rb')
-rw-r--r-- | server.rb | 50 |
1 files changed, 21 insertions, 29 deletions
@@ -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) |