lib/zold/node/front.rb in zold-0.11.7 vs lib/zold/node/front.rb in zold-0.11.8
- old
+ new
@@ -27,10 +27,11 @@
require_relative '../version'
require_relative '../wallet'
require_relative '../log'
require_relative '../id'
require_relative '../http'
+require_relative '../atomic_file'
# The web front of the node.
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2018 Yegor Bugayenko
# License:: MIT
@@ -38,11 +39,11 @@
# Web front
class Front < Sinatra::Base
configure do
set :bind, '0.0.0.0'
set :suppress_messages, true
- set :dump_errors, true
+ set :dump_errors, false
set :start, Time.now
set :lock, false
set :show_exceptions, false
set :server, 'webrick'
set :ignore_score_weakness, false # to be injected at node.rb
@@ -121,10 +122,11 @@
uptime: `uptime`.strip,
threads: "#{Thread.list.select { |t| t.status == 'run' }.count}/#{Thread.list.count}",
wallets: settings.wallets.all.count,
remotes: settings.remotes.all.count,
farm: settings.farm.to_json,
+ entrance: settings.entrance.to_json,
date: `date --iso-8601=seconds -u`.strip,
hours_alive: ((Time.now - settings.start) / (60 * 60)).round(2),
home: 'https://www.zold.io'
)
end
@@ -135,19 +137,19 @@
error 404 unless wallet.exists?
content_type 'application/json'
{
version: VERSION,
score: score.to_h,
- body: File.read(wallet.path)
+ body: AtomicFile.new(wallet.path).read
}.to_json
end
put %r{/wallet/(?<id>[A-Fa-f0-9]{16})/?} do
id = Id.new(params[:id])
wallet = settings.wallets.find(id)
request.body.rewind
body = request.body.read
- if wallet.exists? && File.read(wallet.path) == body
+ if wallet.exists? && AtomicFile.new(wallet.path).read == body
status 304
return
end
settings.entrance.push(id, body, sync: !params[:sync].nil?)
JSON.pretty_generate(