From f09c92f201d00963e4df423454120ce3ad3115f7 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Sun, 13 Sep 2026 11:47:07 +0200 Subject: [PATCH] Restore plain print (no save) as the default for /shipping/zpl and /epson/raw Requiring a name broke the simple 'just print this' API/CI use case -- now that only applies to explicit save/save_and_print, an omitted commit param (or any other value) just prints, matching how these endpoints behaved before the Save/Save & Print buttons were added. --- app.rb | 80 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/app.rb b/app.rb index 3bf9500..5729316 100644 --- a/app.rb +++ b/app.rb @@ -220,21 +220,37 @@ end post '/shipping/zpl' do zpl = params[:zpl].to_s name = params[:save_as].to_s + if zpl.strip.empty? flash 'ZPL text is empty', 'warning' - elsif name.empty? - flash 'Name is required to save', 'warning' - else - LABEL_REPO.save(name: name, type: 'zpl', content: zpl) - if params[:commit] == 'save_and_print' - begin - print_to_datamax(zpl) - flash "Saved '#{name}' and sent to printer", 'success' - rescue => e - flash "Saved '#{name}', but print failed (#{e.message})", 'danger' - end + redirect '/upload' + end + + case params[:commit] + when 'save', 'save_and_print' + if name.empty? + flash 'Name is required to save', 'warning' else - flash "Saved '#{name}'", 'success' + LABEL_REPO.save(name: name, type: 'zpl', content: zpl) + if params[:commit] == 'save_and_print' + begin + print_to_datamax(zpl) + flash "Saved '#{name}' and sent to printer", 'success' + rescue => e + flash "Saved '#{name}', but print failed (#{e.message})", 'danger' + end + else + flash "Saved '#{name}'", 'success' + end + end + else + # No explicit save/save_and_print action -- e.g. a plain API/CI call. + # labelprint stays a "dumb" print API here: just print, nothing saved. + begin + print_to_datamax(zpl) + flash 'ZPL sent to printer', 'success' + rescue => e + flash "ZPL print failed (#{e.message})", 'danger' end end redirect '/upload' @@ -304,21 +320,37 @@ end post '/epson/raw' do content = params[:content].to_s name = params[:save_as].to_s + if content.strip.empty? flash 'Receipt text is empty', 'warning' - elsif name.empty? - flash 'Name is required to save', 'warning' - else - LABEL_REPO.save(name: name, type: 'escpos', content: content) - if params[:commit] == 'save_and_print' - begin - print_raw_escpos(content) - flash "Saved '#{name}' and sent to printer", 'success' - rescue => e - flash "Saved '#{name}', but print failed (#{e.message})", 'danger' - end + redirect '/epson' + end + + case params[:commit] + when 'save', 'save_and_print' + if name.empty? + flash 'Name is required to save', 'warning' else - flash "Saved '#{name}'", 'success' + LABEL_REPO.save(name: name, type: 'escpos', content: content) + if params[:commit] == 'save_and_print' + begin + print_raw_escpos(content) + flash "Saved '#{name}' and sent to printer", 'success' + rescue => e + flash "Saved '#{name}', but print failed (#{e.message})", 'danger' + end + else + flash "Saved '#{name}'", 'success' + end + end + else + # No explicit save/save_and_print action -- e.g. a plain API/CI call. + # labelprint stays a "dumb" print API here: just print, nothing saved. + begin + print_raw_escpos(content) + flash 'Sent to Epson printer', 'success' + rescue => e + flash "Epson print failed (#{e.message})", 'danger' end end redirect '/epson'