diff options
Diffstat (limited to 'helpers.rb')
-rw-r--r-- | helpers.rb | 50 |
1 files changed, 18 insertions, 32 deletions
@@ -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') |