Brother: proxy one brother_ql_web for all QL printers, drop printer switcher
deploy / deploy (push) Successful in 10s

This commit is contained in:
randy committed 2026-10-30 23:52:36 +01:00
1 parent 66300c5278
commit 563772197d
4 files changed
+10 -37

No files matched your search

+2 -3
View File
@@ -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/<printer>/*` -- 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)
+8 -18
View File
@@ -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
-8
View File
@@ -22,14 +22,6 @@
<a class="nav-link border-start <%= 'active' if request.path.start_with?('/repository') %>" href="/repository">Labels</a>
</li>
</ul>
<% if request.path.start_with?('/brother') %>
<span class="navbar-text me-2">Printer:</span>
<div class="d-flex gap-1">
<% BROTHER_PRINTERS.each do |key, info| %>
<a href="/brother/<%= key %>/" class="btn btn-sm <%= request.path.start_with?("/brother/#{key}/") ? 'btn-primary' : 'btn-outline-secondary' %>"><%= info[:label].sub('Brother ', '') %></a>
<% end %>
</div>
<% end %>
</div>
</div>
</nav>
-8
View File
@@ -1,8 +0,0 @@
<h1>Brother printers</h1>
<p>Choose a printer to open its label designer through this server.</p>
<div class="list-group" style="max-width: 400px;">
<% @printers.each do |key, info| %>
<a href="/brother/<%= key %>/" class="btn btn-outline-primary w-100 text-start mb-2"><%= info[:label] %></a>
<% end %>
</div>