add printservant support

This commit is contained in:
radex 2024-01-31 21:47:09 +01:00
parent 97000ad207
commit 1e9de900e0
Signed by: radex
SSH key fingerprint: SHA256:hvqRXAGG1h89yqnS+cyFTLKQbzjWD4uXIqw7Y+0ws30
3 changed files with 7 additions and 7 deletions

View file

@ -1,9 +1,5 @@
FROM ruby:3.0
RUN apt-get update && \
apt-get install -y cups-ipp-utils && \
rm -rf /var/lib/apt/lists/*
# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1

View file

@ -10,4 +10,4 @@ try it out:
GET http://localhost:4567/api/2/preview.pdf?id=abcdef&name=ItemName&owner=OptionalOwner
POST http://localhost:4567/api/2/print?id=abcdef&name=ItemName&owner=OptionalOwner
Make sure to pass either `LABELMAKER_LOCAL_PRINTER_NAME` or `LABELMAKER_IPP_PRINTER_URL`. See top of `main.rb` for all env variables available.
Make sure to pass a printer env. See top of `main.rb` for all env variables available.

View file

@ -15,9 +15,10 @@ CODE_PREFIX = ENV.fetch('LABELMAKER_CODE_PREFIX', 'https://inventory.hackerspace
# ZEBRA_LABEL_SIZE = [100, 60]
LABEL_SIZE = JSON.parse(ENV.fetch('LABELMAKER_LABEL_SIZE', '[89, 36]'))
# NOTE: You can use either local printer or IPP printer, but not both
LOCAL_PRINTER_NAME = ENV.fetch('LABELMAKER_LOCAL_PRINTER_NAME', 'DYMO_LabelWriter_450')
# NOTE: You can use only one of these: local printer, IPP printer, or printservant
LOCAL_PRINTER_NAME = ENV.fetch('LABELMAKER_LOCAL_PRINTER_NAME', '')
IPP_PRINTER_URL = ENV.fetch('LABELMAKER_IPP_PRINTER_URL', '')
PRINTSERVANT_URL = ENV.fetch('LABELMAKER_PRINTSERVANT_URL', '')
def render_label()
short_id = params[:id]
@ -87,6 +88,9 @@ post '/api/2/print' do
system("lpr -P #{LOCAL_PRINTER_NAME.shellescape} #{temp.path.shellescape}", exception: true)
elsif not IPP_PRINTER_URL.empty?
system("ipptool -v -tf #{temp.path.shellescape} -d filetype=application/octet-stream -I #{IPP_PRINTER_URL.shellescape} ipptool-print-job.test", exception: true)
elsif not PRINTSERVANT_URL.empty?
# lmao
system("curl -i -XPOST --data-binary '@#{temp.path.shellescape}' #{PRINTSERVANT_URL.shellescape}", exception: true)
else
status 404
return "No printer configured"