diff options
Diffstat (limited to 'server.rb')
-rw-r--r-- | server.rb | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -19,7 +19,6 @@ get '/' do end get '/outbox/:activity', provides: 'html' do - # outbox_html params['activity'] redirect "https://pdp8.info/social/#{params['activity']}.html" end @@ -69,7 +68,7 @@ helpers do @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') + if @object['id'] and File.readlines(VISITED, chomp: true).include? @object['id'] and !(@activity['type'] = 'Update') return end @@ -88,25 +87,37 @@ helpers do def announce @object ||= @activity['object'] @object = fetch(@object) if @object.is_a? String and @object.match(/^http/) - @object['announce'] = @activity['actor'] if @object - create + if @object['attributedTo'] == 'https://social.pdp8.info/pdp8' + jj @activity + # FileUtils.mkdir_p File.join(INBOX_DIR, 'announce') + # File.open(File.join(INBOX_DIR, 'announce', @activity['published'] + '.json'), 'w+') do |f| + # f.puts @activity.to_json + # end + else + @object['announce'] = @activity['actor'] if @object + create + end end def like @object ||= @activity['object'] @object = fetch(@object) if @object.is_a? String and @object.match(/^http/) - @object['like'] = @activity['actor'] if @object - create + if @object['attributedTo'] == 'https://social.pdp8.info/pdp8' + jj @activity + # FileUtils.mkdir_p File.join(INBOX_DIR, 'like') + # File.open(File.join(INBOX_DIR, 'like', @activity['published'] + '.json'), 'w+') { |f| f.puts @activity.to_json } + else + @object['like'] = @activity['actor'] if @object + create + end end def follow - # 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) if @activity['object']['type'] == 'Follow' update_collection FOLLOWING, @activity['object']['object'] else @@ -122,8 +133,7 @@ helpers do update_collection FOLLOWERS, @activity['object']['actor'], 'delete' when 'Create', 'Announce' file = File.join(INBOX_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'] + FileUtils.rm(file) if file and File.exist? file else p "Error: Cannot undo @activity['object']['type']" jj @activity @@ -147,7 +157,6 @@ helpers do def handle_activity type = @activity['type'].downcase.to_sym - # save_item @activity, File.join(INBOX[:dir], @activity['type'].downcase, activity_name) if ACTIVITIES.include? type send(type) else |