diff options
author | pdp8 <pdp8@pdp8.info> | 2023-06-30 15:42:14 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-06-30 15:42:14 +0200 |
commit | 9d95a49ecd7e2f3e49b3462a281f2b86b406cf41 (patch) | |
tree | cd9695f2e22632e88eb710beeb041458e7ac3a71 /client.rb | |
parent | e328b59ffc2476262dbd076d2478aaade78e649c (diff) |
inbox activities handled by dedicated functions
Diffstat (limited to 'client.rb')
-rw-r--r-- | client.rb | 76 |
1 files changed, 46 insertions, 30 deletions
@@ -1,5 +1,5 @@ # client-server -post "/outbox" do +post "/" do protected! date = Time.now.strftime("%Y-%m-%dT%H:%M:%S") outbox_path = File.join("public/outbox", date + ".json") @@ -65,10 +65,16 @@ post "/outbox" do File.open(outbox_path, "w+") { |f| f.puts create.to_json } File.open(notes_path, "w+") { |f| f.puts create["object"].to_json } + tag.each do |t| + dir = File.join('public','tags',t['name'].sub('#','')) + FileUtils.mkdir_p dir + FileUtils.ln_s File.join('/srv/social/',notes_path), dir + end - recipients.delete "https://www.w3.org/ns/activitystreams#Public" - recipients.each { |r| send_signed create, r } - redirect to(params['redirect']) + #recipients.delete "https://www.w3.org/ns/activitystreams#Public" + #recipients.each { |r| send_signed create, r } + send_signed create #, r } + redirect params['redirect'] end post "/archive" do @@ -77,53 +83,45 @@ post "/archive" do redirect to(params['redirect']) end -post "/delete" do +post "/delete" do # delete not supported by html forms protected! - FileUtils.rm params['file'] - redirect to(params['redirect']) + params['file'] ? FileUtils.rm_f(params['file']) : FileUtils.rm_f(Dir["inbox/*.json"]) + params['redirect'] ? redirect(params['redirect']) : redirect('/') end -post "/delete_all" do +post "/follow" do protected! - FileUtils.rm Dir["inbox/*.json"] - redirect to("/") -end - -post "/follow/*" do - protected! - mention = params['splat'][0] - actor = actor(mention) - return 502 unless actor + actor, mention = parse_follow params['follow'] follow = { "@context" => "https://www.w3.org/ns/activitystreams", - "id" => File.join(SOCIAL_URL, "following", mention + ".json"), + "id" => File.join(SOCIAL_URL, "following", mention+ ".json"), "type" => "Follow", "actor" => ACTOR, - "object" => actor } - send_signed follow, actor - redirect to("/") + "object" => actor, + 'to' => [ actor ] } + send_signed follow#, actor + redirect "/" end -post "/unfollow/*" do +post "/unfollow" do protected! - mention = params['splat'][0] - actor = actor(mention) - return 502 unless actor + actor, mention = parse_follow params['follow'] following_path = File.join("public", "following", mention + ".json") if File.exists?(following_path) undo = { "@context" => "https://www.w3.org/ns/activitystreams", "id" => File.join(SOCIAL_URL + "#undo", SecureRandom.uuid), "type" => "Undo", "actor" => ACTOR, - "object" => JSON.parse(File.read(following_path)) } - send_signed undo, actor + "object" => JSON.parse(File.read(following_path)), + 'to' => [ actor ] } + send_signed undo#, actor FileUtils.rm following_path - redirect to("/") + redirect "/" end end post "/login" do session["client"] = true if OpenSSL::Digest::SHA256.base64digest(params["secret"]) == File.read(".digest").chomp - redirect to("/") + redirect "/" end # private @@ -152,7 +150,9 @@ helpers do def items nr = 0 - files = Dir[File.join(@dir, '*.json')] + Dir['public/notes/*.json'] + p @dir + p Dir[File.join(@dir, '*', '*.json')]# + Dir['public/notes/*.json'] + files = Dir[File.join(@dir, '*', '*.json')] + Dir['public/notes/*.json'] @items = files.sort.collect do |file| item = JSON.parse(File.read(file)) mention = mention(item['attributedTo']) @@ -195,4 +195,20 @@ helpers do erb :item end + def parse_follow follow + case follow + when /^#/ + actor = "https://relay.fedi.buzz/tag/#{follow.sub(/^#/,'')}" + mention = follow + when /^http/ + actor = follow + mention = mention actor + when /^@*\w+@\w+/ + mention = follow + actor = actor(follow) + return 502 unless actor + end + [actor, mention] + end + end |