diff options
-rw-r--r-- | client.rb | 6 | ||||
-rw-r--r-- | helpers.rb | 2 | ||||
-rw-r--r-- | send.rb | 33 | ||||
-rw-r--r-- | server.rb | 5 |
4 files changed, 25 insertions, 21 deletions
@@ -38,6 +38,7 @@ post '/delete' do file = find_file id FileUtils.rm(file) if File.exist? file end + 200 end post '/follow' do @@ -58,14 +59,15 @@ end post '/share' do # TODO protected! - src = find_file INBOX, params['id'] + src = find_file params['id'] object = JSON.parse(File.read(src)) recipients = public recipients << object['attributedTo'] outbox 'Announce', object, recipients - dest = src.sub('/inbox/', '/outbox/') + dest = src.sub('inbox/', 'outbox/') FileUtils.mkdir_p File.dirname(dest) FileUtils.mv src, dest + 200 end post '/login' do @@ -6,7 +6,7 @@ helpers do # add date and id, save def save_activity(activity, box) date = Time.now.utc.iso8601 - activity['published'] = date if box == OUTBOX + activity['published'] ||= date # if box == OUTBOX basename = "#{activity['published']}_#{mention(activity['actor'])}.json" activity_rel_path = File.join(activity['type'].downcase, basename) activity_path = File.join(box[:dir], activity_rel_path) @@ -1,13 +1,11 @@ -post '/' do # TODO +post '/outbox' do # TODO protected! - recipients = public + recipients = params[:public] == 'true' ? public : [] recipients << params[:to] - # content = [] tag = [] params[:content].lines.each do |line| - # line.chomp! tags = line.split(/\s+/).grep(/^#\w+$/) tags.each do |name| tag_url = File.join(TAGS[:url], name.sub('#', '')) @@ -27,7 +25,6 @@ post '/' do # TODO 'name' => mention } end - # content << line end attachment = [] @@ -36,31 +33,33 @@ post '/' do # TODO audio: %w[flac wav mp3 ogg], video: %w[mp4 webm] } - params[:media].each do |_media| - ext = File.extname(line).sub('.', '') - media_type = extensions.select { |_k, v| v.include? ext }.keys[0].to_s + '/' + ext - attachment << { - 'type' => 'Document', - 'mediaType' => media_type, - 'url' => line - } + if params[:media] + params[:media].each do |_media| + ext = File.extname(line).sub('.', '') + media_type = extensions.select { |_k, v| v.include? ext }.keys[0].to_s + '/' + ext + attachment << { + 'type' => 'Document', + 'mediaType' => media_type, + 'url' => line + } + end end object = { 'type' => 'Note', 'attributedTo' => ACTOR, 'inReplyTo' => params[:inReplyTo], - 'content' => "<p>\n#{content.join("\n<br>")}\n</p>", + 'content' => "<p>\n#{params[:content]}\n</p>", 'attachment' => attachment, 'tag' => tag, 'to' => recipients } - activity = outbox 'Create', object, recipients, true + activity = outbox 'Create', object, recipients activity['object']['tag'].each do |tag| next unless tag['type'] == 'Hashtag' - tag_path = File.join(TAGS_DIR, tag['name'].sub('#', '')) + '.json' + tag_path = File.join(TAGS[:dir], tag['name'].sub('#', '')) + '.json' next if File.exist? tag_path File.open(tag_path, 'w+') do |f| @@ -73,7 +72,5 @@ post '/' do # TODO } f.puts tag_collection.to_json end - # update_collection tag_path, activity['object']['id'] end - redirect(params['anchor'] || '/inbox') end @@ -83,6 +83,11 @@ helpers do update_collection FOLLOWERS, @activity['object']['actor'], true end + def update + FileUtils.rm(find_file(@activity['object']['id'])) + create + end + # https://github.com/mastodon/mastodon/blob/main/app/controllers/concerns/signature_verification.rb def verify! # digest |