From a9aa0fcd661a359fd17061704c5cd55770518521 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Sun, 18 Jun 2023 11:20:05 +0200 Subject: return to anchor after archive/delete --- activitypub.rb | 54 ++++++++++++++++++++++++++++++++++++++---------------- public/login.html | 3 +++ public/style.css | 4 ++++ 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/activitypub.rb b/activitypub.rb index 9a57008..e6ab6da 100644 --- a/activitypub.rb +++ b/activitypub.rb @@ -1,6 +1,7 @@ # TODO +# read actor from people.csv +# thread expansion # follow request confirmation -# anchors (return after archive) # boost # federation # client post media @@ -119,25 +120,25 @@ post "/outbox" do # client-server recipients.each { |r| send_signed create, r } end -post "/archive/*" do +post "/archive" do protected! - FileUtils.mv params['splat'][0], "archive/" - redirect to("/") + FileUtils.mv params['file'], "archive/" + redirect to("/##{params['anchor']}") end -post "/delete/*" do +post "/delete" do protected! - FileUtils.rm params['splat'][0] - redirect to("/") + FileUtils.rm params['file'] + redirect to("/archive##{params['anchor']}") end -post "/delete" do +post "/delete_all" do protected! FileUtils.rm Dir["inbox/*.json"] redirect to("/") end -post "/follow/*" do +post "/follow/*/*" do protected! mention = params['splat'][0] actor = actor(mention) @@ -217,6 +218,7 @@ helpers do signature = Base64.decode64(signature_params['signature']) actor = fetch key_id + halt 400 unless actor key = OpenSSL::PKey::RSA.new(actor['publicKey']['publicKeyPem']) comparison = headers.split(' ').map do |signed_params_name| @@ -239,12 +241,15 @@ helpers do end def dir_html dir + nr = 0 items = Dir[File.join(dir, '*.json')].sort.collect do |file| item = JSON.parse(File.read(file)) mention = mention(item['attributedTo']) following_path = File.join('public', 'following', mention + '.json') File.exists?(following_path) ? follow = 'unfollow' : follow = 'follow' + nr += 1 { :id => item['id'], + :nr => nr, :parent => item['inReplyTo'], :file => file, :actor_url => item['attributedTo'], @@ -255,6 +260,7 @@ def dir_html dir :replies => [] } end.compact + items.last[:nr] = items.last[:nr] - 2 threads = [] items.each do |i| if i[:parent].nil? or items.select{|it| it[:id] == i[:parent] }.empty? @@ -269,13 +275,23 @@ def dir_html dir -

#{dir}

- " +

#{dir}" + + if dir == "inbox" + html << "
+ +
" + elsif dir == "archive" + html << "
+ +
" + end + html << "

" threads.each do |item| html << item_html(item,dir) end html << " -
+
@@ -285,7 +301,7 @@ end def item_html item, dir, indent=2 html = " -
+
#{ item[:mention] } 
@@ -295,17 +311,22 @@ def item_html item, dir, indent=2 case dir when "inbox" html << " - + + +
" when "archive" html << " -
+ + +
" end + html << " #{ item[:content].gsub('
','') }" if item[:attachment] @@ -380,7 +401,8 @@ def fetch url, accept = 'application/ld+json; profile="https://www.w3.org/ns/act when Net::HTTPRedirection fetch response['location'], accept, limit-1 else - puts "Unknown response: #{response.code}, #{response.message}\n#{response.code}" + puts "#{url}: #{response.code}, #{response.message}" + #halt 400 end end diff --git a/public/login.html b/public/login.html index 9003b91..8fb479a 100644 --- a/public/login.html +++ b/public/login.html @@ -1,5 +1,8 @@ + + +
diff --git a/public/style.css b/public/style.css index 98d83b5..d72fca9 100644 --- a/public/style.css +++ b/public/style.css @@ -31,6 +31,10 @@ button { border-radius: 0.5em; } +h1 button { + font-size: 0.5em; +} + a { color: #888; } -- cgit v1.2.3