add printservant support
parent
97000ad207
commit
1e9de900e0
|
@ -1,9 +1,5 @@
|
||||||
FROM ruby:3.0
|
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
|
# throw errors if Gemfile has been modified since Gemfile.lock
|
||||||
RUN bundle config --global frozen 1
|
RUN bundle config --global frozen 1
|
||||||
|
|
||||||
|
|
|
@ -10,4 +10,4 @@ try it out:
|
||||||
GET http://localhost:4567/api/2/preview.pdf?id=abcdef&name=ItemName&owner=OptionalOwner
|
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
|
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.
|
||||||
|
|
8
main.rb
8
main.rb
|
@ -15,9 +15,10 @@ CODE_PREFIX = ENV.fetch('LABELMAKER_CODE_PREFIX', 'https://inventory.hackerspace
|
||||||
# ZEBRA_LABEL_SIZE = [100, 60]
|
# ZEBRA_LABEL_SIZE = [100, 60]
|
||||||
LABEL_SIZE = JSON.parse(ENV.fetch('LABELMAKER_LABEL_SIZE', '[89, 36]'))
|
LABEL_SIZE = JSON.parse(ENV.fetch('LABELMAKER_LABEL_SIZE', '[89, 36]'))
|
||||||
|
|
||||||
# NOTE: You can use either local printer or IPP printer, but not both
|
# NOTE: You can use only one of these: local printer, IPP printer, or printservant
|
||||||
LOCAL_PRINTER_NAME = ENV.fetch('LABELMAKER_LOCAL_PRINTER_NAME', 'DYMO_LabelWriter_450')
|
LOCAL_PRINTER_NAME = ENV.fetch('LABELMAKER_LOCAL_PRINTER_NAME', '')
|
||||||
IPP_PRINTER_URL = ENV.fetch('LABELMAKER_IPP_PRINTER_URL', '')
|
IPP_PRINTER_URL = ENV.fetch('LABELMAKER_IPP_PRINTER_URL', '')
|
||||||
|
PRINTSERVANT_URL = ENV.fetch('LABELMAKER_PRINTSERVANT_URL', '')
|
||||||
|
|
||||||
def render_label()
|
def render_label()
|
||||||
short_id = params[:id]
|
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)
|
system("lpr -P #{LOCAL_PRINTER_NAME.shellescape} #{temp.path.shellescape}", exception: true)
|
||||||
elsif not IPP_PRINTER_URL.empty?
|
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)
|
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
|
else
|
||||||
status 404
|
status 404
|
||||||
return "No printer configured"
|
return "No printer configured"
|
||||||
|
|
Loading…
Reference in New Issue