lib/zold/node/front.rb in zold-0.26.15 vs lib/zold/node/front.rb in zold-0.26.16
- old
+ new
@@ -80,10 +80,11 @@
set :remotes, nil # to be injected at node.rb
set :copies, nil # to be injected at node.rb
set :node_alias, nil # to be injected at node.rb
set :zache, nil # to be injected at node.rb
set :async_dir, nil # to be injected at node.rb
+ set :journal_dir, nil # to be injected at node.rb
end
use Rack::Deflater
before do
Thread.current.name = "#{request.request_method}:#{request.url}"
@@ -134,11 +135,11 @@
headers['Access-Control-Allow-Origin'] = '*'
headers[Http::SCORE_HEADER] = score.reduced(Front::MIN_SCORE).to_s
headers['X-Zold-Thread'] = Thread.current.object_id.to_s
unless @start.nil?
if Time.now - @start > 1
- settings.log.info("Slow response to #{request.request_method} #{request.url} \
+ settings.log.debug("Slow response to #{request.request_method} #{request.url} \
from #{request.ip} in #{Age.new(@start, limit: 1)}")
end
headers['X-Zold-Milliseconds'] = ((Time.now - @start) * 1000).round.to_s
end
end
@@ -315,10 +316,47 @@
"Digest: #{wallet.digest}"
].join("\n")
end
end
+ get %r{/wallet/(?<id>[A-Fa-f0-9]{16})\.html} do
+ fetch do |wallet|
+ [
+ '<!DOCTYPE html><html><head>',
+ '<title>' + wallet.id.to_s + '</title>',
+ '<link href="https://cdn.jsdelivr.net/gh/yegor256/tacit@gh-pages/tacit-css-1.4.2.min.css" rel="stylesheet"/>',
+ '<style>table { width: 100%; } td, th { padding: 0.2em .4em }</style>',
+ '</head><body><section>',
+ "<p>#{wallet.network}<br/>",
+ "#{wallet.protocol}<br/>",
+ "#{wallet.id}<br/>",
+ "#{wallet.key.to_pub}</p>",
+ '<table><thead><tr><th>Id</th><th>Date</th><th>Amount</th><th>Wallet</th><th>Details</th></thead>',
+ '<tbody>',
+ wallet.txns.map do |t|
+ [
+ '<tr>',
+ '<td style="color:' + (t.amount.negative? ? 'red' : 'green') + "\">#{t.id}</td>",
+ "<td>#{t.date.utc.iso8601}</td>",
+ '<td style="text-align:right">' + t.amount.to_zld(4) + '</td>',
+ "<td><a href='/wallet/#{t.bnf}.html'>#{t.bnf}</td>",
+ "<td>#{t.details}</td>",
+ '</tr>'
+ ].join
+ end.join,
+ '<p>—<br/>',
+ "Balance: #{wallet.balance.to_zld(8)} ZLD (#{wallet.balance.to_i} zents)<br/>",
+ "Transactions: #{wallet.txns.count}<br/>",
+ "Taxes: #{Tax.new(wallet).paid} paid, the debt is #{Tax.new(wallet).debt}<br/>",
+ "File size: #{Size.new(wallet.size)}/#{wallet.size}, \
+#{Copies.new(File.join(settings.copies, wallet.id)).all.count} copies<br/>",
+ "Modified: #{wallet.mtime.utc.iso8601} (#{Age.new(wallet.mtime.utc.iso8601)} ago)<br/>",
+ "Digest: #{wallet.digest}</p></section></body></html>"
+ ].join
+ end
+ end
+
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})\.bin} do
fetch { |w| send_file(w.path) }
end
get %r{/wallet/(?<id>[A-Fa-f0-9]{16})/copies} do
@@ -438,9 +476,28 @@
DirItems.new(settings.async_dir).fetch.select { |f| /^[0-9a-f]{16}-/.match?(f) }.map do |f|
Wallet.new(File.join(settings.async_dir, f)).mnemo
rescue Errno::ENOENT
f
end.join("\n")
+ end
+
+ get '/journal' do
+ content_type('text/html')
+ [
+ '<!DOCTYPE html><html><head>',
+ '<title>/journal</title>',
+ '<link href="https://cdn.jsdelivr.net/gh/yegor256/tacit@gh-pages/tacit-css-1.4.2.min.css" rel="stylesheet"/>',
+ '</head><body><section>',
+ DirItems.new(settings.journal_dir).fetch.sort.map do |f|
+ "<p><a href='/journal/item?id=#{f}'>#{f}</a></p>"
+ end.join,
+ '</section></body></html>'
+ ].join
+ end
+
+ get '/journal/item' do
+ content_type('text/plain')
+ IO.read(File.join(settings.journal_dir, params[:id]))
end
not_found do
status(404)
content_type('text/plain')