From e120821f2bbcdd4163e9c4b9d249fbf7a7c7287b Mon Sep 17 00:00:00 2001 From: Andy Hayes Date: Thu, 14 Nov 2013 23:02:47 +0000 Subject: [PATCH] add /system/persist-history route to persist history.yml on demand --- lib/dashing.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/dashing.rb b/lib/dashing.rb index a8e9f336..fca5bcfe 100644 --- a/lib/dashing.rb +++ b/lib/dashing.rb @@ -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) @@ -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 @@ -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