summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2024-02-01 12:23:31 +0100
committerpdp8 <pdp8@pdp8.info>2024-02-01 12:23:31 +0100
commit4586c63bd86fe3dad403086b15d5b74b6d67fc92 (patch)
tree41387860e635820738f27071a2d668212d1774d7
parent17fe7f0d25bc99285ddc3dbc153f1f3af9dca335 (diff)
general outbox routes
-rw-r--r--create.rb47
-rw-r--r--helpers.rb15
-rw-r--r--public/style.css3
-rw-r--r--server.rb24
-rw-r--r--views/outbox.erb6
5 files changed, 41 insertions, 54 deletions
diff --git a/create.rb b/create.rb
index 40bfbb8..371f8f8 100644
--- a/create.rb
+++ b/create.rb
@@ -1,5 +1,4 @@
TO_REGEXP = /^to:\s+/i
-CC_REGEXP = /^cc:\s+/i
REPLY_REGEXP = /^inreplyto:\s+/i
ATTACH_REGEXP = /^attach:\s+/i
URL_REGEXP = %r{\Ahttps?://\S+\Z}
@@ -23,11 +22,25 @@ post '/create' do
line.sub(TO_REGEXP, '').split(/\s+/).each do |word|
case word
when 'public'
- to += ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL]
+ to << 'https://www.w3.org/ns/activitystreams#Public'
+ to << FOLLOWERS_URL
when MENTION_REGEXP
- to << actor(word)
+ href = actor(word)
+ m = {
+ 'type' => 'Mention',
+ 'href' => href,
+ 'name' => word
+ }
+ to << href unless to.include? href
+ tag << m unless tag.include? m
when URL_REGEXP
- to << word
+ m = {
+ 'type' => 'Mention',
+ 'href' => word,
+ 'name' => mention(word)
+ }
+ to << word unless to.include? word
+ tag << m unless tag.include? m
end
end
when REPLY_REGEXP
@@ -40,8 +53,8 @@ post '/create' do
'url' => url,
'name' => description
}
- when "\n"
- "<p>\n"
+ when ''
+ content << '<p>'
else # create links
content << line.split(/\s+/).collect do |word|
case word
@@ -55,36 +68,28 @@ post '/create' do
"<a href=\"#{tag_url}\">#{word}</a>"
when MENTION_REGEXP
actor = actor(word)
- tag << {
+ m = {
'type' => 'Mention',
'href' => actor,
'name' => word
}
- to << actor
+ tag << m unless tag.include? m
+ to << actor unless to.include? actor
"<a href=\"#{actor}\">#{word}</a>"
+ when URL_REGEXP
+ "<a href=\"#{word}\">#{word}</a>"
else
word
end
end.join(' ')
- # content << line
end
end
- # https://docs.joinmastodon.org/spec/activitypub/#Mention
- if to.size == 1 # mastodon DM
- m = {
- 'type' => 'Mention',
- 'href' => to[0],
- 'name' => mention(to[0])
- }
- tag << m unless tag.include? m
- end
-
object = {
'to' => to,
'type' => 'Note',
'attributedTo' => ACTOR,
- 'content' => "#{content.join(' ')}"
+ 'content' => "#{content.join('')}"
}
object['inReplyTo'] = inReplyTo unless inReplyTo.empty?
object['attachment'] = attachment unless attachment.empty?
@@ -92,7 +97,7 @@ post '/create' do
# 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 09b0d42..292c71d 100644
--- a/helpers.rb
+++ b/helpers.rb
@@ -162,7 +162,7 @@ helpers do
a = fetch(actor)
return nil unless a
- mention = "#{a['preferredUsername']}@#{URI(actor).host}"
+ mention = "@#{a['preferredUsername']}@#{URI(actor).host}"
cache mention, actor, a
mention
else
@@ -171,11 +171,12 @@ helpers do
end
def actor(mention)
- mention = mention.sub(/^@/, '').chomp
+ mention = mention.chomp
actors = people.select { |p| p[0] == mention }
if actors.empty?
- _, server = mention.split('@')
- a = fetch("https://#{server}/.well-known/webfinger?resource=acct:#{mention}", 'application/jrd+json')
+ server = mention.split('@').last
+ a = fetch("https://#{server}/.well-known/webfinger?resource=acct:#{mention.sub(/^@/, '')}",
+ 'application/jrd+json')
return nil unless a
actor = a['links'].select do |l|
@@ -208,12 +209,6 @@ helpers do
"#{type[0]}/#{ext}"
end
- # def find_file(id)
- # Dir[File.join('*', 'object', '*', '*.json')].find do |f|
- # JSON.load_file(f)['id'] == id
- # end
- # end
-
def find_object(id)
Dir[File.join('*', '**', '*.json')].each do |file|
object = JSON.load_file(file)
diff --git a/public/style.css b/public/style.css
index bef69c9..01d0412 100644
--- a/public/style.css
+++ b/public/style.css
@@ -11,13 +11,12 @@ div.pdp8 {
padding: 1em;
border: 2px solid #333;
border-radius: 1em;
-
}
img,
video {
max-width: 100%;
- max-height: 80vh;
+ height: auto;
display: block;
}
diff --git a/server.rb b/server.rb
index 94729cc..61cbe3c 100644
--- a/server.rb
+++ b/server.rb
@@ -18,15 +18,9 @@ get '/' do
redirect 'https://social.pdp8.info/outbox'
end
-get '/outbox/announce', provides: 'html' do
- @objects = announce_outbox.collect { |a| a['object'] }
- @type = 'announce'
- erb :outbox
-end
-
-get '/outbox/create', provides: 'html' do
- @objects = create_outbox.collect { |a| a['object'] }
- @type = 'create'
+get '/outbox/:activity', provides: 'html' do
+ @activity = params['activity']
+ @objects = outbox(@activity).collect { |a| a['object'] }
erb :outbox
end
@@ -167,20 +161,14 @@ helpers do
File.open(File.join(INBOX[:dir], 'visited'), 'a+') { |f| f.puts @object['id'] }
end
- def create_outbox
- Dir[File.join('outbox', 'create', '*.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
- end
-
- def announce_outbox
- Dir[File.join('outbox', 'announce', '*.json')].collect do |f|
+ def outbox(activity)
+ Dir[File.join('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
end
def public_outbox
- create_outbox + announce_outbox
+ outbox('create') + outbox('announce')
end
# https://github.com/mastodon/mastodon/blob/main/app/controllers/concerns/signature_verification.rb
diff --git a/views/outbox.erb b/views/outbox.erb
index 23adb19..d5e3db5 100644
--- a/views/outbox.erb
+++ b/views/outbox.erb
@@ -10,9 +10,9 @@
<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>
<p>
- <% if @type == 'create' %>
+ <% if @activity == 'create' %>
<h2>posts&nbsp;|&nbsp;<a href='/outbox/announce'>boosts</a></h2>
- <% elsif @type == 'announce' %>
+ <% elsif @activity == 'announce' %>
<h2><a href='/outbox/create'>posts</a>&nbsp;|&nbsp;boosts</h2>
<% end %>
<% @objects.each do |object|
@@ -29,7 +29,7 @@
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>
+ <br><a href='<%= att['url'] %>'><img loading='lazy' width='1024' height='768' alt='<%= att['name'].gsub("'",'&apos;').gsub('"','&quot;') if att['name'] %>' src='<%= att['url'] %>'></a>
<% when /video/ %>
<br><video controls=''><source src='<%= att['url'] %>' type='<%= att['mediaType'] %>'></video>
<% end %>