summaryrefslogtreecommitdiff
path: root/helpers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'helpers.rb')
-rw-r--r--helpers.rb33
1 files changed, 16 insertions, 17 deletions
diff --git a/helpers.rb b/helpers.rb
index c2b0136..72666b1 100644
--- a/helpers.rb
+++ b/helpers.rb
@@ -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("'", '&apos;').gsub('"', '&quot;') : ''
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