Archived
Brother: proxy one brother_ql_web for all QL printers, drop printer switcher
deploy / deploy (push) Successful in 10s
deploy / deploy (push) Successful in 10s
This commit is contained in:
1 parent
66300c5278
commit
563772197d
4 files changed
+10
-37
No files matched your search
+2
-3
@@ -3,7 +3,7 @@
|
|||||||
Unified UI for printing labels/receipts:
|
Unified UI for printing labels/receipts:
|
||||||
|
|
||||||
* Native ZPL printing to a Datamax-ONeil thermal barcode printer
|
* 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
|
* ESC/POS receipt printing to an Epson TM-T20II
|
||||||
|
|
||||||
== Routes
|
== 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/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)
|
* `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)
|
* `/labels` -- shared repository of saved ZPL labels / ESC-POS receipts (list, edit, preview, print, delete)
|
||||||
* `/brother` -- list of Brother QL printers
|
* `/brother/*` -- proxied to brother_ql_web (UI and API alike), the printer is chosen in its label designer
|
||||||
* `/brother/<printer>/*` -- proxied to that printer's brother_ql_web instance (UI and API alike)
|
|
||||||
|
|
||||||
== API usage (e.g. from Gitea Actions)
|
== API usage (e.g. from Gitea Actions)
|
||||||
|
|
||||||
|
|||||||
@@ -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'))
|
LABEL_REPO = LabelRepository.new(File.join(File.dirname(__FILE__), 'data', 'labels'))
|
||||||
|
|
||||||
BROTHER_PRINTERS = {
|
BROTHER_PORT = 8013 # one brother_ql_web for all QL printers (its PRINTERS env)
|
||||||
'ql560' => { port: 8560, label: 'Brother QL-560' },
|
|
||||||
'ql700' => { port: 8700, label: 'Brother QL-700' },
|
|
||||||
'ql1100' => { port: 9100, label: 'Brother QL-1100' }
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
configure do
|
configure do
|
||||||
enable :static
|
enable :static
|
||||||
@@ -223,12 +219,10 @@ helpers do
|
|||||||
res.body
|
res.body
|
||||||
end
|
end
|
||||||
|
|
||||||
# Transparently reverse-proxies the current request to one of the
|
# Transparently reverse-proxies the current request to brother_ql_web, so
|
||||||
# brother_ql_web instances, so all three printers (web UI and API alike)
|
# its web UI and API are reachable through this single sinatra port.
|
||||||
# are reachable through this single sinatra port instead of their own
|
def proxy_to_brother(prefix, path)
|
||||||
# dedicated ports.
|
uri = URI("http://127.0.0.1:#{BROTHER_PORT}#{path}")
|
||||||
def proxy_to_brother(port, prefix, path)
|
|
||||||
uri = URI("http://127.0.0.1:#{port}#{path}")
|
|
||||||
uri.query = request.query_string unless request.query_string.empty?
|
uri.query = request.query_string unless request.query_string.empty?
|
||||||
|
|
||||||
proxied = Net::HTTP.const_get(request.request_method.capitalize).new(uri)
|
proxied = Net::HTTP.const_get(request.request_method.capitalize).new(uri)
|
||||||
@@ -485,15 +479,11 @@ post '/repository/:id/delete' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
get '/brother' do
|
get '/brother' do
|
||||||
@printers = BROTHER_PRINTERS
|
redirect '/brother/'
|
||||||
erb :brother_picker
|
|
||||||
end
|
end
|
||||||
|
|
||||||
%w[get post put delete].each do |verb|
|
%w[get post put delete].each do |verb|
|
||||||
send(verb, '/brother/:printer/*') do
|
send(verb, '/brother/*') do
|
||||||
printer = BROTHER_PRINTERS[params[:printer]]
|
proxy_to_brother('/brother', '/' + params[:splat].first)
|
||||||
halt 404, 'unknown printer' unless printer
|
|
||||||
|
|
||||||
proxy_to_brother(printer[:port], "/brother/#{params[:printer]}", '/' + params[:splat].first)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -22,14 +22,6 @@
|
|||||||
<a class="nav-link border-start <%= 'active' if request.path.start_with?('/repository') %>" href="/repository">Labels</a>
|
<a class="nav-link border-start <%= 'active' if request.path.start_with?('/repository') %>" href="/repository">Labels</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -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>
|
|
||||||
Reference in new issue
Block a user