summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2023-09-14 20:20:26 +0200
committerpdp8 <pdp8@pdp8.info>2023-09-14 20:20:26 +0200
commit44967ae9f605ca37b6d88e4e8b11a9cf1fdc2b57 (patch)
tree0060d8c1f44a202dc145c211ea7b2230f686acbf
parent49de4bbdf6d68fef2133f1399131286decae3039 (diff)
note objects fixed, verify reactivated
-rw-r--r--create.rb10
-rw-r--r--helpers.rb14
-rw-r--r--server.rb2
-rw-r--r--views/outbox.erb41
4 files changed, 53 insertions, 14 deletions
diff --git a/create.rb b/create.rb
index 8e221c8..40e1357 100644
--- a/create.rb
+++ b/create.rb
@@ -4,6 +4,7 @@ ATTACH_REGEXP = /^attach:\s+/i
URL_REGEXP = %r{\Ahttps?://\S+\Z}
MENTION_REGEXP = /\A@\w+@\S+\Z/
HASHTAG_REGEXP = /\A#\w+\Z/
+# COMMENT_REGEXP = /^<!*--/
post '/create' do
protected!
@@ -18,6 +19,10 @@ post '/create' do
request.body.read.each_line do |line|
line.chomp!
case line
+ when /^<!--$/
+ next
+ when /^-->$/
+ next
when TO_REGEXP
line.sub(TO_REGEXP, '').split(/\s+/).each do |word|
case word
@@ -71,9 +76,10 @@ post '/create' do
object['inReplyTo'] = inReplyTo unless inReplyTo.empty?
object['attachment'] = attachment unless attachment.empty?
object['tag'] = tag unless tag.empty?
- jj object
+ # p to
+ # jj object
- # create_activity 'Create', object, to
+ create_activity 'Create', object, to
200
end
diff --git a/helpers.rb b/helpers.rb
index 89ce7d4..536a7c6 100644
--- a/helpers.rb
+++ b/helpers.rb
@@ -17,8 +17,6 @@ helpers do
'to' => to,
'object' => object
}
- activity_path = File.join(OUTBOX[:dir], rel_path)
- save_item activity, activity_path
unless activity['object'].is_a? String
object_rel_path = File.join('object', object['type'].downcase, "#{date}.json")
@@ -51,6 +49,8 @@ helpers do
end
end
end
+ activity_path = File.join(OUTBOX[:dir], rel_path)
+ save_item activity, activity_path
send_activity activity, activity_path
end
@@ -80,6 +80,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}\""
+ p inbox
# Net::HTTP fails with OpenSSL error
curl(
"-X POST -H 'Host: #{uri.host}' -H 'Date: #{httpdate}' -H 'Digest: #{digest}' -H 'Signature: #{signed_header}' --data-binary '@#{activity_path}'", inbox
@@ -207,13 +208,4 @@ helpers do
JSON.load_file(f)['id'] == id
end
end
-
- # def find_id(id, return_filename = true)
- # Dir[File.join('**', '*.json')].find do |f|
- # content = JSON.load_file(f)
- # if content['id'] == id
- # return_filename ? f : content
- # end
- # end
- # end
end
diff --git a/server.rb b/server.rb
index b0f3bd9..0807375 100644
--- a/server.rb
+++ b/server.rb
@@ -10,7 +10,7 @@ post '/inbox' do
end
# deleted actors return 403 => verification error
halt 200 if @activity['type'] == 'Delete' and @activity['actor'] == @activity['object']
- # verify! # pixelfed sends unsigned activities???
+ verify! # pixelfed sends unsigned activities???
handle_activity
200
end
diff --git a/views/outbox.erb b/views/outbox.erb
new file mode 100644
index 0000000..db840f4
--- /dev/null
+++ b/views/outbox.erb
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html lang='en'>
+ <head>
+ <meta charset="UTF-8">
+ <title>pdp8 social</title>
+ <link rel="icon" type="image/png" href="/pdp8.png">
+ <link rel='stylesheet' type='text/css' href='/style.css'>
+ </head>
+ <body>
+ <h1><a href="https://social.pdp8.info/pdp8">pdp8@social.pdp8.info</a></h1>
+ music, pictures and videos: <a href="https://pdp8.info">https://pdp8.info</a>
+ <% @activities.each do |activity|
+ file = find_file activity['object']['id']
+ @object = JSON.load_file file if file and File.exists? file
+ if @object
+ mention = mention @object['attributedTo'] %>
+ <div class='pdp8'>
+ <p><b><a href='<%= @object['attributedTo'] %>' target='_blank'><%= mention %></a></b>&nbsp;
+ <em><%= @object['published'] %></em>
+ <% if activity['type'] == 'Announce' %>
+ &nbsp;(<em>announced</em>)
+ <% end %>
+ <p>
+ <%= @object['content']%>
+ <% if @object['attachment']
+ @object['attachment'].each do |att|
+ case att['mediaType']
+ when /audio/ %>
+ <br><audio controls=''><source src='<%= att['url'] %>' type='<%= att['mediaType'] %>'></audio>
+ <% when /image/ %>
+ <br><a href='<%= att['url'] %>'><img src='<%= att['url'] %>' alt='<%= att['name'].gsub("'",'&apos;').gsub('"','&quot;') if att['name'] %>'></a>
+ <% when /video/ %>
+ <br><video controls=''><source src='<%= att['url'] %>' type='<%= att['mediaType'] %>'></video>
+ <% end %>
+ <% end %>
+ <% end %>
+ </div>
+ <% end %>
+ <% end %>
+ </body>
+</html>