diff options
Diffstat (limited to 'client.rb')
-rw-r--r-- | client.rb | 37 |
1 files changed, 19 insertions, 18 deletions
@@ -16,24 +16,10 @@ post '/delete' do 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'] - outbox 'Follow', params['id'], [params['id']] + create_activity 'Follow', params['id'], [params['id']] 200 end @@ -48,8 +34,8 @@ post '/unfollow' do "actor": 'https://social.pdp8.info/pdp8', "object": params['id'] } - outbox 'Undo', activity, [params['id']] - update_collection FOLLOWING, params['id'], true + create_activity 'Undo', activity, [params['id']] + update_collection FOLLOWING, params['id'], 'delete' 200 end @@ -60,13 +46,28 @@ post '/share' do # TODO recipients = ['https://www.w3.org/ns/activitystreams#Public'] recipients += JSON.load_file(FOLLOWERS)['orderedItems'] recipients << object['attributedTo'] - outbox 'Announce', object, recipients + create_activity 'Announce', object, recipients dest = src.sub('inbox/', 'outbox/') FileUtils.mkdir_p File.dirname(dest) FileUtils.mv src, dest 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 '/login' do session['client'] = (OpenSSL::Digest::SHA256.base64digest(params['secret']) == File.read('.digest').chomp) 200 |