Restore plain print (no save) as the default for /shipping/zpl and /epson/raw
deploy / deploy (push) Successful in 9s
deploy / deploy (push) Successful in 9s
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.
This commit is contained in:
1 parent
368bf670b9
commit
f09c92f201
1 file changed
+34
-2
@@ -220,9 +220,15 @@ 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?
|
||||
redirect '/upload'
|
||||
end
|
||||
|
||||
case params[:commit]
|
||||
when 'save', 'save_and_print'
|
||||
if name.empty?
|
||||
flash 'Name is required to save', 'warning'
|
||||
else
|
||||
LABEL_REPO.save(name: name, type: 'zpl', content: zpl)
|
||||
@@ -237,6 +243,16 @@ post '/shipping/zpl' do
|
||||
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'
|
||||
end
|
||||
|
||||
@@ -304,9 +320,15 @@ 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?
|
||||
redirect '/epson'
|
||||
end
|
||||
|
||||
case params[:commit]
|
||||
when 'save', 'save_and_print'
|
||||
if name.empty?
|
||||
flash 'Name is required to save', 'warning'
|
||||
else
|
||||
LABEL_REPO.save(name: name, type: 'escpos', content: content)
|
||||
@@ -321,6 +343,16 @@ post '/epson/raw' do
|
||||
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'
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user