diff options
author | pdp8 <pdp8@pdp8.info> | 2023-06-18 11:20:05 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-06-18 11:20:05 +0200 |
commit | a9aa0fcd661a359fd17061704c5cd55770518521 (patch) | |
tree | ca35fcc2319fc7fc70f398be1c86eebc88359591 /activitypub.rb | |
parent | 0c3a5b8565fb7148714696eedd3d5adf4fc68641 (diff) |
return to anchor after archive/delete
Diffstat (limited to 'activitypub.rb')
-rw-r--r-- | activitypub.rb | 54 |
1 files changed, 38 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 <link rel='stylesheet' type='text/css' href='/style.css'> </head> <body> - <h1>#{dir}</h1> - " + <h1>#{dir}" + + if dir == "inbox" + html << "<form action='archive' method='get'> + <button>archive</button> + </form>" + elsif dir == "archive" + html << "<form action='/' method='get'> + <button>inbox</button> + </form>" + end + html << " </h1> " threads.each do |item| html << item_html(item,dir) end html << " - <form action='delete' method='post'> + <form action='delete_all' method='post'> <button>Delete all</button> </form> </body> @@ -285,7 +301,7 @@ end def item_html item, dir, indent=2 html = " - <div style='margin-left:#{indent}em'> + <div style='margin-left:#{indent}em' id='#{item[:nr]}'> <b><a href='#{ item[:actor_url] }', target='_blank'>#{ item[:mention] }</a></b> <form action='#{ File.join item[:follow], item[:mention] }' method='post'> <button>#{ item[:follow].capitalize }</button> @@ -295,17 +311,22 @@ def item_html item, dir, indent=2 case dir when "inbox" html << " - <form action='#{ File.join 'archive', item[:file] }' method='post'> + <form action='/archive' method='post'> + <input type='hidden' name='file' id='file' value='#{item[:file]}' /> + <input type='hidden' name='anchor' id='anchor' value='#{item[:nr]}' /> <button>Archive</button> </form> " when "archive" html << " - <form action='#{ File.join 'delete', item[:file] }' method='post'> + <form action='/delete' method='post'> + <input type='hidden' name='file' id='file' value='#{item[:file]}' /> + <input type='hidden' name='anchor' id='anchor' value='#{item[:nr]}' /> <button>Delete</button> </form> " end + html << " #{ item[:content].gsub('<br />','') }" 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 |