diff options
-rw-r--r-- | client.rb | 26 | ||||
-rw-r--r-- | create.rb | 27 |
2 files changed, 14 insertions, 39 deletions
@@ -1,20 +1,4 @@ # client-server -# ['/inbox/object', '/outbox/object'].each do |path| -# get path do -# protected! -# Dir[File.join(path.sub('/', ''), '*', '*.json')].collect { |f| JSON.load_file(f) }.to_json -# end -# end - -# post '/delete' do -# protected! -# params['id'].each do |id| -# file, object = find_object id -# halt 404 unless file and File.exist?(file) -# FileUtils.rm(file) -# end -# 200 -# end post '/follow' do protected! @@ -41,19 +25,9 @@ end post '/announce' do # TODO protected! - # src, object = find_object params['id'] - # object = JSON.load_file(src) - # to = ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL] - # to << object['attributedTo'] - # create_activity 'Announce', object, to - # src, object = find_object params['id'] - # object = JSON.load_file(src) to = ['https://www.w3.org/ns/activitystreams#Public', FOLLOWERS_URL] to << params['attributedTo'] create_activity 'Announce', params['id'], to - # dest = src.sub('inbox/', 'outbox/') - # FileUtils.mkdir_p File.dirname(dest) - # FileUtils.rm src 200 end @@ -1,10 +1,10 @@ TO_REGEXP = /^to:\s+/i +CC_REGEXP = /^cc:\s+/i REPLY_REGEXP = /^inreplyto:\s+/i ATTACH_REGEXP = /^attach:\s+/i URL_REGEXP = %r{\Ahttps?://\S+\Z} MENTION_REGEXP = /\A@\w+@\S+\Z/ HASHTAG_REGEXP = /\A#\w+\Z/ -# COMMENT_REGEXP = /^<!*--/ post '/create' do protected! @@ -19,10 +19,6 @@ post '/create' do request.body.read.each_line do |line| line.chomp! case line - when /^<!--$/ - next - when /^-->$/ - next when TO_REGEXP line.sub(TO_REGEXP, '').split(/\s+/).each do |word| case word @@ -40,14 +36,14 @@ post '/create' do url, description = line.sub(ATTACH_REGEXP, '').split(/\s+/, 2) attachment << { 'type' => 'Document', - 'mediaType' => media_type(url), + 'mediaType' => media_type(url), # TODO: query with curl HEAD 'url' => url, 'name' => description } + when "\n" + "<p>\n" else # create links - # single quotes in html invalidate digest, reason unknown - line.split(/\s+/).each do |word| - word = word.gsub('<p>', '').gsub('</p>', '') + content << line.split(/\s+/).collect do |word| case word when HASHTAG_REGEXP tag_url = File.join('https://social.pdp8.info', 'tags', word.sub('#', '')) @@ -56,6 +52,7 @@ post '/create' do 'href' => tag_url, 'name' => word } + "<a href=\"#{tag_url}\">#{word}</a>" when MENTION_REGEXP actor = actor(word) tag << { @@ -63,9 +60,13 @@ post '/create' do 'href' => actor, 'name' => word } + to << actor + "<a href=\"#{actor}\">#{word}</a>" + else + word end - end - content << line + end.join(' ') + # content << line end end @@ -89,9 +90,9 @@ post '/create' do object['attachment'] = attachment unless attachment.empty? object['tag'] = tag unless tag.empty? # p to - # jj object + jj object - create_activity 'Create', object, to + # create_activity 'Create', object, to 200 end |