summaryrefslogtreecommitdiff
path: root/client.rb
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-09-04 10:41:32 +0200
committerpdp8 <pdp8@pdp8.info>2023-09-04 10:41:32 +0200
commit9ecb046ed70c9431f97eab1d761aa9fb22f8f73c (patch)
tree58cf2e4420dd0888dd6a0c94b44d0665a67d819f /client.rb
parent485d71e69cb5b56d3ccf8b5eb82ef6af9d172485 (diff)
ignore visited objects
Diffstat (limited to 'client.rb')
-rw-r--r--client.rb42
1 files changed, 29 insertions, 13 deletions
diff --git a/client.rb b/client.rb
index 0ebd3aa..61d1ac3 100644
--- a/client.rb
+++ b/client.rb
@@ -10,29 +10,45 @@ post '/delete' do
protected!
params['id'].each do |id|
file = find_file id
+ halt 404 unless file
# if file.match(%r{outbox/}) # find/delete activity
- Dir[File.join 'outbox', 'announce', '*'].each do |announce_file|
- announce = JSON.load_file(announce_file)
- next unless announce['object']['id'] == id
+ %w[inbox outbox].each do |box|
+ Dir[File.join box, 'announce', '*.json'].each do |announce_file|
+ announce = JSON.load_file(announce_file)
+ next unless announce['object']['id'] == id
- outbox 'Undo', announce, announce['to']
- FileUtils.rm(announce_file)
- end
- Dir[File.join 'outbox', 'create', '*'].each do |create_file|
- create = JSON.load_file(create_file)
- next unless create['object']['id'] == id
+ outbox 'Undo', announce, announce['to']
+ FileUtils.rm(announce_file)
+ end
+ Dir[File.join box, 'create', '*.json'].each do |create_file|
+ create = JSON.load_file(create_file)
+ next unless create['object']['id'] == id
- object = JSON.load_file(file)
- outbox 'Delete', object, object['to']
- FileUtils.rm(create_file)
+ object = JSON.load_file(file)
+ outbox 'Delete', object, object['to']
+ FileUtils.rm(create_file)
+ end
end
- # end
FileUtils.rm(file) if File.exist? file
end
200
end
+post '/undo' do # TODO: generalize for announce
+ protected!
+ 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']
+ outbox 'Undo', params['id'], activity['to']
+ FileUtils.rm(object_file)
+ FileUtils.rm(f)
+ end
+ 200
+end
+
post '/follow' do
protected!
params['id'] = actor params['mention'] if params['mention']