summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--application.rb1
-rw-r--r--client.rb6
-rw-r--r--create.rb2
-rw-r--r--helpers.rb64
-rw-r--r--server.rb27
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 += '<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 += "&nbsp;<a class='item' href='/#{c}.html'>#{c}</a>"
+ end
+ html += "&nbsp;<a class='item current' href='/social/create.html'>social</a>"
+ html += "&nbsp;<a class='item' href='/rss.xml'>rss</a>"
+ html += "&nbsp;<a id='menu' href='#' onclick='show_vertical_menu()'>&equiv;</a>"
+ html += "</nav><div class='post'><h1><a href='https://social.pdp8.info/pdp8'>@pdp8@social.pdp8.info</a></h1><h2>"
+ html += if activity == 'create'
+ "posts&nbsp;|&nbsp;<a href='/social/announce.html'>boosts</a>"
+ elsif activity == 'announce'
+ "<a href='/social/create.html'>posts</a>&nbsp;|&nbsp;boosts"
+ end
+ html += '</h2></div>'
+ 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 += "<div class='post'>"
+ if activity == 'announce'
+ html += "<b><a href='#{object['attributedTo']}' target='_blank'>#{mention}</a></b>&nbsp;"
+ end
+ html += "<em>#{object['published']}</em>
+ #{object['content']}"
+ if object['attachment']
+ object['attachment'].each do |att|
+ w = 1024
+ h = 768
+ case att['mediaType']
+ when /audio/
+ html += "<br><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 += "<br><a href='#{att['url']}'><img loading='lazy' width='#{w}' height='#{h}' "
+ alt = att['name'] ? att['name'].gsub("'", '&apos;').gsub('"', '&quot;') : ''
+ 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 += "<br><video width='#{w}' height='#{h}' controls><source src='#{att['url']}' type='#{att['mediaType']}'></video>"
+ end
+ end
+ end
+ html += '</div>'
+ end
+ html += File.read('/home/ch/src/publish/html/tail.html')
+ %w[pdp8 pdp8-test].each do |d|
+ outdir = "/srv/www/#{d}/social"
+ out = File.join(outdir, activity + '.html')
+ File.open(out, 'w+') { |f| f.puts(html) }
+ puts `/etc/profiles/per-user/ch/bin/tidy -iqm -w 0 #{out} 2>&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)