From e4e4dedf8ca423e110787657799137444ca0f8fe Mon Sep 17 00:00:00 2001 From: pdp8 Date: Sat, 10 Feb 2024 00:09:34 +0100 Subject: outbox moved to website --- application.rb | 1 - client.rb | 6 ++++++ create.rb | 2 +- helpers.rb | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ server.rb | 27 ++++++++++++++++--------- 5 files changed, 88 insertions(+), 12 deletions(-) diff --git a/application.rb b/application.rb index 5236685..39e47c7 100644 --- a/application.rb +++ b/application.rb @@ -27,7 +27,6 @@ VISITED = File.join(INBOX[:dir], 'visited') ACTIVITIES = %i[create announce follow accept undo delete like update move] CONTENT_TYPE = 'application/activity+json' -# CONTENT_TYPE = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' use Rack::Protection diff --git a/client.rb b/client.rb index d19c6fc..891a1d8 100644 --- a/client.rb +++ b/client.rb @@ -28,6 +28,7 @@ post '/announce' do # TODO to = ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL] to << params['attributedTo'] create_activity 'Announce', params['id'], to + outbox_html('announce') 200 end @@ -41,6 +42,11 @@ post '/undo' do # TODO: generalize for announce create_activity 'Undo', params['id'], activity['to'] FileUtils.rm(activity_file) FileUtils.rm(object_file) + if activity_file.match 'create' + outbox_html('create') + elsif activity_file.match 'announce' + outbox_html('announce') + end end 200 end diff --git a/create.rb b/create.rb index 371f8f8..32ec480 100644 --- a/create.rb +++ b/create.rb @@ -94,10 +94,10 @@ post '/create' do object['inReplyTo'] = inReplyTo unless inReplyTo.empty? object['attachment'] = attachment unless attachment.empty? object['tag'] = tag unless tag.empty? - # p to jj object create_activity 'Create', object, to + outbox_html('create') 200 end diff --git a/helpers.rb b/helpers.rb index 292c71d..4bce51f 100644 --- a/helpers.rb +++ b/helpers.rb @@ -215,4 +215,68 @@ helpers do return [file, object] if object['id'] == id end end + + def outbox_html(activity) + html = File.read('/home/ch/src/publish/html/head.html') + html += '

@pdp8@social.pdp8.info

" + html += if activity == 'create' + "posts | boosts" + elsif activity == 'announce' + "posts | boosts" + end + html += '

' + Dir[File.join(SOCIAL_DIR, 'outbox', activity, '*.json')].collect do |f| + JSON.load_file(f) + end.select { |a| a['to'].include?('https://www.w3.org/ns/activitystreams#Public') }.sort_by { |a| a['published'] }.reverse.collect { |a| a['object'] }.each do |object| + object = fetch(object) if object.is_a? String + mention = mention object['attributedTo'] + html += "
" + if activity == 'announce' + html += "#{mention} " + end + html += "#{object['published']} + #{object['content']}" + if object['attachment'] + object['attachment'].each do |att| + w = 1024 + h = 768 + case att['mediaType'] + when /audio/ + html += "
" + when /image/ + if activity == 'create' + w, h = `/etc/profiles/per-user/ch/bin/identify -format "%w %h" #{att['url'].sub( + 'https://media.pdp8.info', '/srv/media' + )}`.chomp.split(' ') end + html += "
att['name']&1` + end + end end diff --git a/server.rb b/server.rb index 61cbe3c..0d92f8c 100644 --- a/server.rb +++ b/server.rb @@ -19,14 +19,11 @@ get '/' do end get '/outbox/:activity', provides: 'html' do - @activity = params['activity'] - @objects = outbox(@activity).collect { |a| a['object'] } - erb :outbox + redirect "https://pdp8.info/social/#{params['activity']}.html" end get '/outbox', provides: 'html' do - redirect 'https://social.pdp8.info/outbox/create' - erb :outbox + redirect 'https://pdp8.info/social/create.html' end get '/outbox' do @@ -39,7 +36,7 @@ get '/outbox' do end get '/pdp8', provides: 'html' do - redirect 'https://social.pdp8.info/outbox/create' + redirect 'https://pdp8.info/social/create.html' end get '/pdp8' do @@ -82,7 +79,10 @@ helpers do end def like - announce + @object ||= @activity['object'] + @object = fetch(@object) if @object.is_a? String and @object.match(/^http/) + @object['like'] = @activity['actor'] if @object + create end def follow @@ -153,12 +153,19 @@ helpers do @object = fetch(@object) if @object.is_a? String and @object.match(/^http/) return unless @object - if @activity['type'] != 'Update' && (@object['id'] and File.readlines(VISITED, chomp: true).include? @object['id']) - return + + # if @activity['type'] != 'Update' && (@object['id'] and File.readlines(VISITED, chomp: true).include? @object['id']) + # return + # end + if @object['id'] and File.readlines(VISITED, chomp: true).include? @object['id'] + return unless @activity['type'] = 'Update' + + FileUtils.rm_f find_object(@object['id'])[0] + end save_item @object, File.join(INBOX[:dir], 'object', @object['type'].downcase, activity_name) - File.open(File.join(INBOX[:dir], 'visited'), 'a+') { |f| f.puts @object['id'] } + File.open(VISITED, 'a+') { |f| f.puts @object['id'] } end def outbox(activity) -- cgit 1.4.1