From 6100f9971b74ee4d3449155beb881a69017a296d Mon Sep 17 00:00:00 2001 From: pdp8 Date: Sun, 24 Sep 2023 12:28:40 +0200 Subject: undo reactivated, object names without published date, find_object helper --- client.rb | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'client.rb') diff --git a/client.rb b/client.rb index 8af00c9..7b93c83 100644 --- a/client.rb +++ b/client.rb @@ -9,7 +9,7 @@ end post '/delete' do protected! params['id'].each do |id| - file = find_file id + file, object = find_object id halt 404 unless file and File.exist?(file) FileUtils.rm(file) end @@ -53,20 +53,19 @@ post '/share' do # TODO 200 end -# post '/undo' do # TODO: generalize for announce -# protected! -# activity_file = find_file(params['id']) -# Dir[File.join('outbox', '*', '*.json')].each do |f| -# activity = JSON.load_file(f) -# next unless activity['id'] == params['id'] -# -# object_file = find_file activity['object']['id'] -# create_activity 'Undo', params['id'], activity['to'] -# FileUtils.rm(object_file) -# FileUtils.rm(f) -# end -# 200 -# end +post '/undo' do # TODO: generalize for announce + protected! + Dir[File.join('outbox', '*', '*.json')].each do |activity_file| + activity = JSON.load_file(activity_file) + next unless activity['id'] == params['id'] + + object_file = find_file activity['object']['id'] + create_activity 'Undo', params['id'], activity['to'] + FileUtils.rm(activity_file) + FileUtils.rm(object_file) + end + 200 +end post '/login' do session['client'] = (OpenSSL::Digest::SHA256.base64digest(params['secret']) == File.read('.digest').chomp) -- cgit v1.2.3