diff options
author | pdp8 <pdp8@pdp8.info> | 2023-06-28 18:55:27 +0200 |
---|---|---|
committer | pdp8 <pdp8@pdp8.info> | 2023-06-28 18:55:27 +0200 |
commit | e328b59ffc2476262dbd076d2478aaade78e649c (patch) | |
tree | 758f134e1b68af8a52fd2559c9fe704a62b9a040 /client.rb | |
parent | dfaac96870ac6a86ebb0b5e5c9365e1e0ef6e5bc (diff) |
digest login, refactoring
Diffstat (limited to 'client.rb')
-rw-r--r-- | client.rb | 40 |
1 files changed, 3 insertions, 37 deletions
@@ -122,7 +122,7 @@ post "/unfollow/*" do end post "/login" do - session["client"] = true if params["secret"] == File.read(".pwd").chomp + session["client"] = true if OpenSSL::Digest::SHA256.base64digest(params["secret"]) == File.read(".digest").chomp redirect to("/") end @@ -168,7 +168,7 @@ helpers do :follow => follow, :content => item['content'], :attachment => item['attachment'], - :indent => 2, + :indent => 0, :replies => [] } end.compact @@ -183,7 +183,7 @@ helpers do @threads << i else @items.select{|it| it[:id] == i[:parent] }.each do |it| - i[:indent] = it[:indent] + 2 + i[:indent] = it[:indent] + 4 it[:replies] << i end end @@ -195,38 +195,4 @@ helpers do erb :item end - def people - File.read('cache/people.tsv').split("\n").collect {|l| l.chomp.split("\t")} - end - - def mention actor - person = people.select{|p| p[1] == actor} - if person.empty? - a = fetch(actor) - return nil unless a - mention = "#{a["preferredUsername"]}@#{URI(actor).host}" - File.open('cache/people.tsv','a'){|f| f.puts "#{mention}\t#{actor}"} - mention - else - person[0][0] - end - end - - def actor mention - mention = mention.sub(/^@/, '').chomp - actors = people.select{|p| p[0] == mention} - if actors.empty? - user, server = mention.split("@") - a = fetch("https://#{server}/.well-known/webfinger?resource=acct:#{mention}", "application/jrd+json") - return nil unless a - actor = a["links"].select { |l| - l["rel"] == "self" - }[0]["href"] - File.open('cache/people.tsv','a'){|f| f.puts "#{mention}\t#{actor}"} - actor - else - actors[0][1] - end - end - end |