This commit is contained in:
wiktor 2023-03-08 23:36:34 +01:00
parent 0e42dfb93b
commit 47d0a2210f
1 changed files with 14 additions and 14 deletions

28
main.rb
View File

@ -84,7 +84,7 @@ end
DYMO_LABEL_SIZE = [89, 36]
ZEBRA_LABEL_SIZE = [50, 30]
def render_test(dict_or_api, extra, item_or_label_id, size: ZEBRA_LABEL_SIZE)
def render_label(dict_or_api, extra, item_or_label_id, size: ZEBRA_LABEL_SIZE)
if dict_or_api
item = item_or_label_id
else
@ -139,14 +139,14 @@ set :bind, '0.0.0.0'
get '/api/1/preview/:id.pdf' do
headers["Content-Type"] = "application/pdf; charset=utf8"
render_test(false,"qr",params["id"])
render_label(false,"qr",params["id"])
end
get '/api/1/preview/:id.png' do
headers["Content-Type"] = "image/png"
img = Magick::ImageList.new()
img = img.from_blob(render_test(false,"qr",params["id"])){ self.density = 200 }.first
img = img.from_blob(render_label(false,"qr",params["id"])){ self.density = 200 }.first
img.format = 'png'
img.background_color = 'white'
img.to_blob
@ -154,14 +154,14 @@ end
post '/api/1/print/:id' do
temp = Tempfile.new('labelmaker')
temp.write(render_test(false,"qr", params["id"]))
temp.write(render_label(false,"qr", params["id"]))
temp.close
system("lpr -P Zebra #{temp.path}")
end
get '/api/1/templates/preview/:id' do
headers["Content-Type"] = "application/pdf; charset=utf8"
render_test(true, "img", templates[params["id"]])
render_label(true, "img", templates[params["id"]])
end
get '/api/1/templates/print/:id' do
@ -174,12 +174,12 @@ end
get '/api/1/nametag/preview/:id' do
headers["Content-Type"] = "application/pdf; charset=utf8"
render_test(true, "img",{"text" => params['id'], "image" => "assets/hswro.svg"})
render_label(true, "img",{"text" => params['id'], "image" => "assets/hswro.svg"})
end
get '/api/1/nametag/print/:id' do
temp = Tempfile.new('labelmaker')
temp.write(render_test(true, "img",{"text" => params['id'], "image" => "assets/hswro.svg"}))
temp.write(render_label(true, "img",{"text" => params['id'], "image" => "assets/hswro.svg"}))
temp.close
system("lpr -P Zebra #{temp.path}")
end
@ -187,13 +187,13 @@ end
get '/api/1/customitem/preview/:owner/:name' do
test = {"owner" => params["owner"], "short_id" => "test", "name" => params["name"]}
headers["Content-Type"] = "application/pdf; charset=utf8"
render_test(true,"blank",test)
render_label(true,"blank",test)
end
get '/api/1/customitem/print/:owner/:name' do
test = {"owner" => params["owner"], "short_id" => "test", "name" => params["name"]}
temp = Tempfile.new('labelmaker')
temp.write(render_test(true,"blank",test))
temp.write(render_label(true,"blank",test))
temp.close
system("lpr -P Zebra #{temp.path}")
end
@ -203,19 +203,19 @@ end
get '/api/1/dupatest/preview' do
test = {"owner" => "test", "short_id" => "test", "name" => "test", "image" => "assets/glider.svg"}
headers["Content-Type"] = "application/pdf; charset=utf8"
render_test(true,"img",test)
render_label(true,"img",test)
end
get '/api/1/testgift/preview' do
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
headers["Content-Type"] = "application/pdf; charset=utf8"
render_test(true,"img",test)
render_label(true,"img",test)
end
get '/api/1/testgift/print' do
test = {"name" => "Przedmiot podarował: lynx, małpa, franek", "image" => "assets/gift.svg"}
temp = Tempfile.new('labelmaker')
temp.write(render_test(true, "img",test))
temp.write(render_label(true, "img",test))
temp.close
system("lpr -P Zebra #{temp.path}")
end
@ -223,13 +223,13 @@ end
get '/api/1/testshow' do
test = {"owner" => "grzegorz_brzęczyszczykiewicz", "short_id" => "wszczebrzeszyniechrzaszczbrzmiwtrzcinie", "name" => "pchnąć w tę łódź jeża lub ośm skrzyń fig"}
headers["Content-Type"] = "application/pdf; charset=utf8"
render_test(true, "qr", test)
render_label(true, "qr", test)
end
get '/api/1/testprint' do
test = {"owner" => "grzegorz_brzęczyszczykiewicz", "short_id" => "wszczebrzeszyniechrzaszczbrzmiwtrzcinie", "name" => "pchnąć w tę łódź jeża lub ośm skrzyń fig"}
temp = Tempfile.new('labelmaker')
temp.write(render_test(true,"qr",test))
temp.write(render_label(true,"qr",test))
temp.close
system("lpr -P Zebra #{temp.path}")
end