diff options
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 |