Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Add route to persist history.yml on demand #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions lib/dashing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

# Persist history in tmp file at exit
at_exit do
File.open(settings.history_file, 'w') do |f|
f.puts settings.history.to_yaml
end
persist_history
end

if File.exists?(settings.history_file)
Expand Down Expand Up @@ -109,6 +107,19 @@ def protected!
end
end

post '/system/persist-history' do
request.body.rewind
body = JSON.parse(request.body.read)
auth_token = body.delete("auth_token")
if !settings.auth_token || settings.auth_token == auth_token
persist_history
204 # response without entity body
else
status 401
"Invalid API key\n"
end
end

not_found do
send_file File.join(settings.public_folder, '404.html')
end
Expand Down Expand Up @@ -154,6 +165,12 @@ def tilt_html_engines
end
end

def persist_history
File.open(settings.history_file, 'w') do |f|
f.puts settings.history.to_yaml
end
end

settings_file = File.join(settings.root, 'config/settings.rb')
if (File.exists?(settings_file))
require settings_file
Expand Down