From 9781dda58c3d2926f928544a8155d493fc2f1ca2 Mon Sep 17 00:00:00 2001 From: pdp8 Date: Sun, 13 Aug 2023 10:31:26 +0200 Subject: activity/object saving, send activities from file --- create.rb | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) (limited to 'create.rb') diff --git a/create.rb b/create.rb index b418c5b..6a6dd4e 100644 --- a/create.rb +++ b/create.rb @@ -33,11 +33,14 @@ post '/create' do # TODO elsif line.match(/\A==\Z/) attachment = lines[i + 1..-1].collect do |url| url.chomp! - { + url, name = url.split(/\s+/, 2) + doc = { 'type' => 'Document', 'mediaType' => media_type(url), 'url' => url } + doc['name'] = name if name + doc end break else @@ -70,41 +73,19 @@ post '/create' do # TODO content << line end end + content.shift while content[0] == '

' object = { 'to' => to, 'type' => 'Note', 'attributedTo' => ACTOR, - 'content' => "#{content.join("\n")}" + 'content' => "#{content.join(' ')}" } object['inReplyTo'] = inReplyTo unless inReplyTo.empty? object['attachment'] = attachment unless attachment.empty? object['tag'] = tag unless tag.empty? - activity = outbox 'Create', object, to + outbox 'Create', object, to - if activity['object']['tag'] - activity['object']['tag'].each do |tag| - next unless tag['type'] == 'Hashtag' - - tag_path = File.join(TAGS[:dir], tag['name'].sub('#', '')) + '.json' - tag_collection = if File.exist? tag_path - JSON.parse(File.read(tag_path)) - else - { - '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => tag['href'], - 'type' => 'OrderedCollection', - 'totalItems' => 0, - 'orderedItems' => [] - } - end - tag_collection['orderedItems'] << activity['object']['id'] - tag_collection['totalItems'] = tag_collection['orderedItems'].size - File.open(tag_path, 'w+') do |f| - f.puts tag_collection.to_json - end - end - end 200 end -- cgit v1.2.3