diff options
author | pdp8 <pdp8@pdp8.info> | 2023-08-13 10:31:26 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-08-13 10:31:26 +0200 |
commit | 9781dda58c3d2926f928544a8155d493fc2f1ca2 (patch) | |
tree | 74d709ee31d90ff02e6c55c7d9ab473e5eff50a2 /create.rb | |
parent | 3a8be7b1606885b3b94bc22a6d775a6527e1c07d (diff) |
activity/object saving, send activities from file
Diffstat (limited to 'create.rb')
-rw-r--r-- | create.rb | 33 |
1 files changed, 7 insertions, 26 deletions
@@ -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] == '<p>' 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 |