diff options
author | pdp8 <pdp8@pdp8.info> | 2023-07-29 20:59:48 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-07-29 20:59:48 +0200 |
commit | c50f749a2685a3e7608cec8730f5fe79de4676ac (patch) | |
tree | 75192aac75c86a6593737b1bdeb211f0799a5a8e /helpers.rb | |
parent | 3daf30b0a3837d3d8becb0baceed580e92403ce6 (diff) |
POST /create
Diffstat (limited to 'helpers.rb')
-rw-r--r-- | helpers.rb | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -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 |