From c50f749a2685a3e7608cec8730f5fe79de4676ac Mon Sep 17 00:00:00 2001 From: pdp8 Date: Sat, 29 Jul 2023 20:59:48 +0200 Subject: POST /create --- helpers.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'helpers.rb') diff --git a/helpers.rb b/helpers.rb index 5344606..7a56ec1 100644 --- a/helpers.rb +++ b/helpers.rb @@ -11,11 +11,13 @@ helpers do activity_rel_path = File.join(activity['type'].downcase, basename) activity_path = File.join(box[:dir], activity_rel_path) if box == OUTBOX + return unless activity['to'].include? 'https://www.w3.org/ns/activitystreams#Public' # save only public messages + activity['id'] = File.join(box[:url], activity_rel_path) activity['object']['published'] = date unless activity['object'].is_a? String end # save object - save_object activity['object'], box if activity['object'] && activity['object']['type'] && !activity['object']['id'] + save_object activity['object'], box if %w[Create Announce Update].include? activity['type'] # save activity FileUtils.mkdir_p File.dirname(activity_path) File.open(activity_path, 'w+') { |f| f.puts activity.to_json } @@ -24,12 +26,12 @@ helpers do def save_object(object, box) object = fetch(object) if object.is_a? String and object.match(/^http/) - return unless object + return unless object # and object['type'] != 'Person' object['@context'] = 'https://www.w3.org/ns/activitystreams' basename = "#{object['published']}_#{mention(object['attributedTo'])}.json" object_rel_path = File.join 'object', object['type'].downcase, basename - object['id'] = File.join box[:url], object_rel_path if box == OUTBOX + object['id'] ||= File.join box[:url], object_rel_path # if box == OUTBOX object_path = File.join box[:dir], object_rel_path FileUtils.mkdir_p File.dirname(object_path) File.open(object_path, 'w+') { |f| f.puts object.to_json } @@ -122,4 +124,15 @@ helpers do sharedInbox = a['endpoints']['sharedInbox'] if a['endpoints'] && a['endpoints']['sharedInbox'] File.open('public/people.tsv', 'a') { |f| f.puts "#{mention}\t#{actor}\t#{sharedInbox}" } end + + def media_type(url) # TODO: extend extensions + extensions = { + image: %w[jpeg jpg png tiff], + audio: %w[flac wav mp3 ogg aiff], + video: %w[mp4 webm] + } + ext = File.extname(url).sub('.', '').downcase + type = extensions.find { |_k, v| v.include? ext } + "#{type[0]}/#{ext}" + end end -- cgit v1.2.3