diff options
-rw-r--r-- | helpers.rb | 33 | ||||
-rw-r--r-- | server.rb | 8 |
2 files changed, 20 insertions, 21 deletions
@@ -1,9 +1,17 @@ require 'English' helpers do - def save_item(item, dir) - return unless @object['id'] + def save_inbox(item) + return unless item['id'] - path = File.join(dir, @object['id'].sub('https://', '')) + path = File.join(INBOX_DIR, item['id'].sub('https://', '')) + FileUtils.mkdir_p File.dirname(path) + File.open(path, 'w+') { |f| f.puts item.to_json } + end + + def save_outbox(item) + return unless item['id'] + + path = item['id'].sub(SOCIAL_URL, SOCIAL_DIR) FileUtils.mkdir_p File.dirname(path) File.open(path, 'w+') { |f| f.puts item.to_json } end @@ -27,7 +35,7 @@ helpers do object['@context'] = 'https://www.w3.org/ns/activitystreams' object['id'] = File.join(OUTBOX_URL, object_rel_path) object['published'] = date - save_item activity['object'], OUTBOX_DIR + save_outbox activity['object'] if object['tag'] object['tag'].each do |tag| next unless tag['type'] == 'Hashtag' @@ -52,7 +60,7 @@ helpers do end end end - save_item activity, OUTBOX_DIR + save_outbox activity send_activity activity, File.join(OUTBOX_DIR, rel_path) end @@ -211,15 +219,6 @@ helpers do "#{type[0]}/#{ext}" end - # def find_object(id) - # Dir[File.join('*', '**', '*.json')].each do |file| - # object = JSON.load_file(file) - # return [file, object] if object['id'] == id - # rescue JSON::ParserError - # puts "Invalid JSON in #{file}" - # end - # end - def outbox_html(activity) html = File.read('/home/ch/src/publish/html/head.html') html += '<nav>' @@ -255,13 +254,13 @@ helpers do h = 768 case att['mediaType'] when /audio/ - html += "<br><audio controls><source src='#{att['url']}' type='#{att['mediaType']}'></audio>" + html += "<p><audio controls><source src='#{att['url']}' type='#{att['mediaType']}'></audio>" when /image/ if activity == 'create' w, h = `/etc/profiles/per-user/ch/bin/identify -format "%w %h" #{att['url'].sub( 'https://media.pdp8.info', '/srv/media' )}`.chomp.split(' ') end - html += "<br><a href='#{att['url']}'><img loading='lazy' width='#{w}' height='#{h}' " + html += "<p><a href='#{att['url']}'><img loading='lazy' width='#{w}' height='#{h}' " alt = att['name'] ? att['name'].gsub("'", ''').gsub('"', '"') : '' html += "alt='#{alt}' src='#{att['url']}'></a>" when /video/ @@ -270,7 +269,7 @@ helpers do 'https://media.pdp8.info', '/srv/media' )}`.chomp.split(',') end - html += "<br><video width='#{w}' height='#{h}' controls><source src='#{att['url']}' type='#{att['mediaType']}'></video>" + html += "<p><video width='#{w}' height='#{h}' controls><source src='#{att['url']}' type='#{att['mediaType']}'></video>" end end end @@ -44,7 +44,7 @@ get '/pdp8' do end get '/.well-known/webfinger' do - halt 404 unless request['resource'] == "acct:#{MENTION}" + halt 404 unless request.params['resource'] == "acct:#{MENTION}" send_file(WEBFINGER, type: 'application/jrd+json') end @@ -72,7 +72,7 @@ helpers do return end - save_item @object, INBOX_DIR + save_inbox @object File.open(VISITED, 'a+') { |f| f.puts @object['id'] } return unless @object and @object['inReplyTo'] and @count < 5 @@ -120,7 +120,7 @@ helpers do when 'Follow' update_collection FOLLOWERS, @activity['object']['actor'], 'delete' when 'Create', 'Announce' - file = File.join(dir, @activity['object']['id'].sub('https://', '')) + file = File.join(INBOX_DIR, @activity['object']['id'].sub('https://', '')) # file, object = find_object @activity['object']['object'] FileUtils.rm(file) if file and File.exist? file # and @activity['actor'] == object['attributedTo'] else @@ -136,7 +136,7 @@ helpers do end def delete - file = File.join(dir, @activity['object']['id'].sub('https://', '')) + file = File.join(INBOX_DIR, @activity['object']['id'].sub('https://', '')) # file, object = find_object(@activity['object']['id']) FileUtils.rm(file) if file and File.exist? file # and @activity['actor'] == @activity['object']['attributedTo'] end |