diff options
author | pdp8 <pdp8@pdp8.info> | 2024-08-10 00:29:02 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2024-08-10 00:29:02 +0200 |
commit | 7f3023df5be705436544b5724a6b83c2717aa0b8 (patch) | |
tree | 99687362f33cdf6c8f83f2cdd2d20875d8df0480 | |
parent | 060492722d6137225a9e00add6c7f150d014927d (diff) |
improved outbox html, background sending
-rw-r--r-- | client.rb | 5 | ||||
-rw-r--r-- | helpers.rb | 50 | ||||
-rw-r--r-- | server.rb | 4 |
3 files changed, 22 insertions, 37 deletions
@@ -38,12 +38,11 @@ post '/undo' do # TODO: generalize for announce activity = JSON.load_file(activity_file) next unless activity['id'] == params['id'] - object_file = File.join(dir, activity['object']['id'].sub('https://', '')) - # object_file, object = find_object activity['object']['id'] create_activity 'Undo', params['id'], activity['to'] FileUtils.rm(activity_file) - FileUtils.rm(object_file) if activity_file.match 'create' + object_file = File.join(SOCIAL_DIR, activity['object']['id'].sub('https://', '')) + FileUtils.rm(object_file) outbox_html('create') elsif activity_file.match 'announce' outbox_html('announce') @@ -1,3 +1,4 @@ +require_relative '/home/ch/src/wgen/lib' require 'English' helpers do def save_inbox(item) @@ -61,7 +62,11 @@ helpers do end end save_outbox activity - send_activity activity, File.join(OUTBOX_DIR, rel_path) + pid = fork do + settings.running_server = nil # http://stackoverflow.com/a/38934866/1021515 + send_activity activity, File.join(OUTBOX_DIR, rel_path) + end + Process.detach pid end def send_activity(activity, activity_path) @@ -90,8 +95,7 @@ helpers do signature = Base64.strict_encode64(keypair.sign(OpenSSL::Digest.new('SHA256'), string)) signed_header = "keyId=\"#{ACTOR}#main-key\",algorithm=\"rsa-sha256\",headers=\"(request-target) host date digest content-type\",signature=\"#{signature}\"" - # Net::HTTP fails with OpenSSL error - curl( + curl( # Net::HTTP fails with OpenSSL error "-X POST -H 'Host: #{uri.host}' -H 'Date: #{httpdate}' -H 'Digest: #{digest}' -H 'Signature: #{signed_header}' --data-binary '@#{activity_path}'", inbox ) end @@ -220,63 +224,45 @@ helpers do end def outbox_html(activity) - html = File.read('/home/ch/src/publish/html/head.html') - html += '<nav>' - html += "<a id='logo' href='/about.html'><img src='/pdp8.png' alt='pdp8'></a>" - %w[music pictures videos climbing code contact].each do |c| - html += " <a class='item' href='/#{c}.html'>#{c}</a>" - end - html += " <a class='item current' href='/social/create.html'>social</a>" - html += " <a class='item' href='/rss.xml'>rss</a>" - html += " <a id='menu' href='#' onclick='show_vertical_menu()'>≡</a>" - html += "</nav><div class='post'><h1><a href='https://social.pdp8.info/pdp8'>@pdp8@social.pdp8.info</a></h1><h2>" + html = File.read(File.join(SNIPPETS, 'head.html')) + html += nav 'social' + html += "<h1><a href='https://social.pdp8.info/pdp8'>@pdp8@social.pdp8.info</a></h1><h2>" html += if activity == 'create' "posts | <a href='/social/announce.html'>boosts</a>" elsif activity == 'announce' "<a href='/social/create.html'>posts</a> | boosts" end - html += '</h2></div>' + html += '</h2>' 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 if object mention = mention object['attributedTo'] - html += "<div class='post'>" + html += '<section>' + html += "<h3>#{object['published']}</h3>" if activity == 'announce' html += "<b><a href='#{object['attributedTo']}' target='_blank'>#{mention}</a></b> " end - html += "<em>#{object['published']}</em> - #{object['content']}" + html += object['content'] if object['attachment'] object['attachment'].each do |att| - w = 1024 - h = 768 case att['mediaType'] when /audio/ html += "<p><audio controls><source src='#{att['url']}' type='#{att['mediaType']}'></audio>" 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 += "<p><a href='#{att['url']}'><img loading='lazy' width='#{w}' height='#{h}' " + html += "<p><a href='#{att['url']}'><img loading='lazy' " alt = att['name'] ? att['name'].gsub("'", ''').gsub('"', '"') : '' html += "alt='#{alt}' src='#{att['url']}'></a>" when /video/ - if activity == 'create' - w, h = `ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=p=0 #{att['url'].sub( - 'https://media.pdp8.info', '/srv/media' - )}`.chomp.split(',') - end - html += "<p><video width='#{w}' height='#{h}' controls><source src='#{att['url']}' type='#{att['mediaType']}'></video>" + html += "<p><video controls><source src='#{att['url']}' type='#{att['mediaType']}'></video>" end end end end - html += '</div>' + html += '</section>' end - html += File.read('/home/ch/src/publish/html/tail.html') + html += File.read(File.join(SNIPPETS, 'tail.html')) %w[pdp8 pdp8-test].each do |d| outdir = "/srv/www/#{d}/social" out = File.join(outdir, activity + '.html') @@ -19,6 +19,7 @@ get '/' do end get '/outbox/:activity', provides: 'html' do + # outbox_html params['activity'] redirect "https://pdp8.info/social/#{params['activity']}.html" end @@ -137,8 +138,7 @@ helpers do def delete file = File.join(INBOX_DIR, @activity['object']['id'].sub('https://', '')) - # file, object = find_object(@activity['object']['id']) - FileUtils.rm(file) if file and File.exist? file # and @activity['actor'] == @activity['object']['attributedTo'] + FileUtils.rm_f(file) if file end def move |