diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | client.rb | 28 | ||||
-rw-r--r-- | helpers.rb | 2 | ||||
-rw-r--r-- | server.rb | 19 |
4 files changed, 30 insertions, 20 deletions
@@ -4,3 +4,4 @@ inbox public/*/ *csv +*~ @@ -2,10 +2,10 @@ # client-server -['/inbox', '/outbox'].each do |path| +['/inbox/threads', '/outbox/threads'].each do |path| get path do protected! - box = path.sub('/', '') + box = path.sub('/', '').sub('/threads', '') collection = Dir[File.join(box, 'object', '*', '*.json')].collect { |f| JSON.parse(File.read(f)) } threads = [] collection.collect! do |object| @@ -42,20 +42,18 @@ end post '/follow' do protected! - actor, = parse_follow params['follow'] - outbox 'Follow', actor, [actor] + params['id'] = actor params['mention'] if params['mention'] + outbox 'Follow', params['id'], [params['id']] end post '/unfollow' do protected! - actor, mention = parse_follow params['follow'] - Dir[File.join(OUTBOX[:dir], 'follow', '*.json')].each do |f| - activity = JSON.parse(File.read(f)) - if activity['object'] == actor - outbox 'Undo', activity, [actor] - update_collection FOLLOWING, actor, true - end - end + params['id'] = actor params['mention'] if params['mention'] + following = Dir[File.join(OUTBOX[:dir], 'follow', '*.json')].collect { |f| JSON.parse(File.read(f)) } + activity = following.find { |a| a['object'] == params['id'] } + activity ||= save_activity({ 'type' => 'Follow', 'actor' => ACTOR, 'object' => params['id'] }, OUTBOX) # recreate activity for old/deleted follows + outbox 'Undo', activity, [params['id']] + update_collection FOLLOWING, params['id'], true end post '/share' do # TODO @@ -64,7 +62,7 @@ post '/share' do # TODO object = JSON.parse(File.read(src)) recipients = public recipients << object['attributedTo'] - # outbox 'Announce', object, recipients + outbox 'Announce', object, recipients dest = src.sub('/inbox/', '/outbox/') FileUtils.mkdir_p File.dirname(dest) FileUtils.mv src, dest @@ -80,9 +78,9 @@ helpers do end def find_file(id) - Dir[File.join('*', 'object', '*', '*.json')].select do |f| + Dir[File.join('*', 'object', '*', '*.json')].find do |f| JSON.parse(File.read(f))['id'] == id - end[0] + end end def public @@ -12,7 +12,7 @@ helpers do activity_path = File.join(box[:dir], activity_rel_path) if box == OUTBOX activity['id'] = File.join(box[:url], activity_rel_path) - activity['object']['published'] = date + activity['object']['published'] = date unless activity['object'].is_a? String end # save object save_object activity['object'], box if activity['object'] && activity['object']['type'] && !activity['object']['id'] @@ -24,19 +24,30 @@ get '/' do redirect 'https://pdp8.info' end +get '/outbox' do + files = Dir[File.join('outbox', 'create', '*.json')] + Dir[File.join('outbox', 'announce', '*.json')] + activities = files.collect { |f| JSON.parse(File.read(f)) } + ids = activities.sort_by { |a| a['published'] }.collect { |a| a['id'] } + { '@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => 'https://social.pdp8.info/outbox', + 'type' => 'OrderedCollection', + 'totalItems' => ids.size, + 'orderedItems' => ids }.to_json +end + get '/pdp8', provides: 'html' do redirect 'https://pdp8.info' end +get '/pdp8' do + send_file(File.join(PUBLIC_DIR, 'pdp8.json'), type: CONTENT_TYPE) +end + get '/.well-known/webfinger' do halt 404 unless request['resource'] == "acct:#{MENTION}" send_file(WEBFINGER, type: 'application/jrd+json') end -get '/pdp8' do - send_file(File.join(PUBLIC_DIR, 'pdp8.json'), type: CONTENT_TYPE) -end - ['/following', '/followers'].each do |path| get path do send_file(File.join(PUBLIC_DIR, path) + '.json', type: CONTENT_TYPE) |