From 88518c5a4fa4fa9d841bb0d1c8add9fa2234530c Mon Sep 17 00:00:00 2001 From: pdp8 Date: Wed, 20 Dec 2023 11:20:50 +0100 Subject: follow, announce, delete fixed --- client.rb | 59 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 27 deletions(-) (limited to 'client.rb') diff --git a/client.rb b/client.rb index 01124bc..e0a5746 100644 --- a/client.rb +++ b/client.rb @@ -1,20 +1,20 @@ # client-server -['/inbox/object', '/outbox/object'].each do |path| - get path do - protected! - Dir[File.join(path.sub('/', ''), '*', '*.json')].collect { |f| JSON.load_file(f) }.to_json - end -end +# ['/inbox/object', '/outbox/object'].each do |path| +# get path do +# protected! +# Dir[File.join(path.sub('/', ''), '*', '*.json')].collect { |f| JSON.load_file(f) }.to_json +# end +# end -post '/delete' do - protected! - params['id'].each do |id| - file, object = find_object id - halt 404 unless file and File.exist?(file) - FileUtils.rm(file) - end - 200 -end +# post '/delete' do +# protected! +# params['id'].each do |id| +# file, object = find_object id +# halt 404 unless file and File.exist?(file) +# FileUtils.rm(file) +# end +# 200 +# end post '/follow' do protected! @@ -29,26 +29,31 @@ post '/unfollow' do following = Dir[File.join(OUTBOX[:dir], 'follow', '*.json')].collect { |f| JSON.load_file(f) } activity = following.find { |a| a['object'] == params['id'] } activity ||= { - "@context": 'https://www.w3.org/ns/activitystreams', - "type": 'Follow', - "actor": 'https://social.pdp8.info/pdp8', - "object": params['id'] + '@context' => 'https://www.w3.org/ns/activitystreams', + 'type' => 'Follow', + 'actor' => 'https://social.pdp8.info/pdp8', + 'object' => params['id'] } create_activity 'Undo', activity, [params['id']] update_collection FOLLOWING, params['id'], 'delete' 200 end -post '/share' do # TODO +post '/announce' do # TODO protected! - src, object = find_object params['id'] - object = JSON.load_file(src) + # src, object = find_object params['id'] + # object = JSON.load_file(src) + # to = ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL] + # to << object['attributedTo'] + # create_activity 'Announce', object, to + # src, object = find_object params['id'] + # object = JSON.load_file(src) to = ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL] - to << object['attributedTo'] - create_activity 'Announce', object, to - dest = src.sub('inbox/', 'outbox/') - FileUtils.mkdir_p File.dirname(dest) - FileUtils.mv src, dest + to << params['attributedTo'] + create_activity 'Announce', params['id'], to + # dest = src.sub('inbox/', 'outbox/') + # FileUtils.mkdir_p File.dirname(dest) + # FileUtils.rm src 200 end -- cgit v1.2.3