summaryrefslogtreecommitdiff
path: root/server.rb
diff options
context:
space:
mode:
Diffstat (limited to 'server.rb')
-rw-r--r--server.rb32
1 files changed, 24 insertions, 8 deletions
diff --git a/server.rb b/server.rb
index 2bcb102..b0f3bd9 100644
--- a/server.rb
+++ b/server.rb
@@ -17,13 +17,16 @@ end
# public
get '/' do
- redirect 'https://pdp8.info'
+ redirect 'https://social.pdp8.info/outbox'
+end
+
+get '/outbox', provides: 'html' do
+ @activities = public_outbox
+ erb :outbox
end
get '/outbox' do
- files = Dir[File.join('outbox', 'create', '*.json')] + Dir[File.join('outbox', 'announce', '*.json')]
- activities = files.collect { |f| JSON.load_file(f) }
- ids = activities.sort_by { |a| a['published'] }.collect { |a| a['id'] }
+ ids = public_outbox.collect { |a| a['id'] }
{ '@context' => 'https://www.w3.org/ns/activitystreams',
'id' => 'https://social.pdp8.info/outbox',
'type' => 'OrderedCollection',
@@ -32,7 +35,7 @@ get '/outbox' do
end
get '/pdp8', provides: 'html' do
- redirect 'https://pdp8.info'
+ redirect 'https://social.pdp8.info/outbox'
end
get '/pdp8' do
@@ -99,7 +102,7 @@ helpers do
update_collection FOLLOWERS, @activity['object']['actor'], 'delete'
when 'Create', 'Announce'
file = find_file @activity['object']['object']
- FileUtils.rm(file) if file
+ FileUtils.rm(file) if file and File.exist? file
else
p "Cannot undo @activity['object']['type']"
jj @activity
@@ -109,13 +112,13 @@ helpers do
def update
file = find_file(@activity['object']['id'])
- FileUtils.rm(file) if file
+ FileUtils.rm(file) if file and File.exist? file
create
end
def delete
file = find_file(@activity['object']['id'])
- FileUtils.rm(file) if file
+ FileUtils.rm(file) if file and File.exist? file
end
def move
@@ -151,6 +154,19 @@ helpers do
File.open(File.join(INBOX[:dir], 'visited'), 'a+') { |f| f.puts @object['id'] }
end
+ def public_outbox
+ # files = Dir[File.join('outbox', 'create', '*.json')] + Dir[File.join('outbox', 'announce', '*.json')]
+ create = 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
+ announce = Dir[File.join('outbox', 'announce', '*.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
+ # activities = files.collect { |f| JSON.load_file(f) }
+ # activities.select { |a| a['to'].include?('https://www.w3.org/ns/activitystreams#Public') }.sort_by { |a| a['published'] }
+ create + announce
+ end
+
# https://github.com/mastodon/mastodon/blob/main/app/controllers/concerns/signature_verification.rb
def verify!
# digest