diff --git a/README.adoc b/README.adoc index 7f5392f..f94582f 100644 --- a/README.adoc +++ b/README.adoc @@ -3,7 +3,7 @@ Unified UI for printing labels/receipts: * Native ZPL printing to a Datamax-ONeil thermal barcode printer -* A proxy/switcher in front of three https://github.com/DL6ER/brother_ql_web[brother_ql_web] instances, one per Brother QL printer +* A proxy in front of https://github.com/DL6ER/brother_ql_web[brother_ql_web] (port 8013), which drives all Brother QL printers * ESC/POS receipt printing to an Epson TM-T20II == Routes @@ -17,8 +17,7 @@ Unified UI for printing labels/receipts: * `POST /epson/raw` -- print already-formatted ESC/POS mnemonic notation (see "API usage" below) * `POST /epson/test-print` -- print an Epson capability test page (text sizes, barcode, QR, raster image) * `/labels` -- shared repository of saved ZPL labels / ESC-POS receipts (list, edit, preview, print, delete) -* `/brother` -- list of Brother QL printers -* `/brother//*` -- proxied to that printer's brother_ql_web instance (UI and API alike) +* `/brother/*` -- proxied to brother_ql_web (UI and API alike), the printer is chosen in its label designer == API usage (e.g. from Gitea Actions) diff --git a/app.rb b/app.rb index fc9f37b..4afaa12 100644 --- a/app.rb +++ b/app.rb @@ -29,11 +29,7 @@ PRINTER_DEVICE_EPSON = '/dev/usb/lp_epson' # see /etc/udev/rules.d/99-epson.rule LABEL_REPO = LabelRepository.new(File.join(File.dirname(__FILE__), 'data', 'labels')) -BROTHER_PRINTERS = { - 'ql560' => { port: 8560, label: 'Brother QL-560' }, - 'ql700' => { port: 8700, label: 'Brother QL-700' }, - 'ql1100' => { port: 9100, label: 'Brother QL-1100' } -}.freeze +BROTHER_PORT = 8013 # one brother_ql_web for all QL printers (its PRINTERS env) configure do enable :static @@ -223,12 +219,10 @@ helpers do res.body end - # Transparently reverse-proxies the current request to one of the - # brother_ql_web instances, so all three printers (web UI and API alike) - # are reachable through this single sinatra port instead of their own - # dedicated ports. - def proxy_to_brother(port, prefix, path) - uri = URI("http://127.0.0.1:#{port}#{path}") + # Transparently reverse-proxies the current request to brother_ql_web, so + # its web UI and API are reachable through this single sinatra port. + def proxy_to_brother(prefix, path) + uri = URI("http://127.0.0.1:#{BROTHER_PORT}#{path}") uri.query = request.query_string unless request.query_string.empty? proxied = Net::HTTP.const_get(request.request_method.capitalize).new(uri) @@ -485,15 +479,11 @@ post '/repository/:id/delete' do end get '/brother' do - @printers = BROTHER_PRINTERS - erb :brother_picker + redirect '/brother/' end %w[get post put delete].each do |verb| - send(verb, '/brother/:printer/*') do - printer = BROTHER_PRINTERS[params[:printer]] - halt 404, 'unknown printer' unless printer - - proxy_to_brother(printer[:port], "/brother/#{params[:printer]}", '/' + params[:splat].first) + send(verb, '/brother/*') do + proxy_to_brother('/brother', '/' + params[:splat].first) end end diff --git a/views/_navbar.erb b/views/_navbar.erb index 60da952..e3441d2 100644 --- a/views/_navbar.erb +++ b/views/_navbar.erb @@ -22,14 +22,6 @@ Labels - <% if request.path.start_with?('/brother') %> - Printer: -
- <% BROTHER_PRINTERS.each do |key, info| %> - "><%= info[:label].sub('Brother ', '') %> - <% end %> -
- <% end %> diff --git a/views/brother_picker.erb b/views/brother_picker.erb deleted file mode 100644 index c4cedcc..0000000 --- a/views/brother_picker.erb +++ /dev/null @@ -1,8 +0,0 @@ -

Brother printers

-

Choose a printer to open its label designer through this server.

- -
- <% @printers.each do |key, info| %> - <%= info[:label] %> - <% end %> -