From ce7f5aad2a4eefe2bb2b5c5799bec835306d0727 Mon Sep 17 00:00:00 2001 From: seb Date: Sun, 1 Nov 2026 00:20:26 +0100 Subject: [PATCH] u --- src/api/routes/article/media.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/api/routes/article/media.js b/src/api/routes/article/media.js index 7afb0a7..640c177 100644 --- a/src/api/routes/article/media.js +++ b/src/api/routes/article/media.js @@ -4,6 +4,7 @@ import express from 'express'; import { renderLabel } from 'react-canvas-label-editor'; import * as db from '../../../db/article.js'; import * as printerDb from '../../../db/printer.js'; +import * as agentprinterDb from '../../../db/agentprinter.js'; import * as labeltemplateDb from '../../../db/labeltemplate.js'; import { AVIF_BODY_LIMIT, @@ -364,7 +365,8 @@ export function register(app, basePath = '') { if (skuError) return res.status(400).json({ error: skuError }); const sku = parsedSku; - const { templateId, printerId, quantity } = req.body ?? {}; + const rawPrinterId = req.body?.printerId ?? req.body?.agentprinterId; + const { templateId, quantity } = req.body ?? {}; if (templateId === undefined || templateId === null) { return res.status(400).json({ error: 'templateId is required' }); @@ -373,10 +375,10 @@ export function register(app, basePath = '') { return res.status(400).json({ error: 'templateId must be an integer' }); } - if (printerId === undefined || printerId === null) { + if (rawPrinterId === undefined || rawPrinterId === null) { return res.status(400).json({ error: 'printerId is required' }); } - if (typeof printerId !== 'number' || !Number.isInteger(printerId) || printerId <= 0) { + if (typeof rawPrinterId !== 'number' || !Number.isInteger(rawPrinterId) || rawPrinterId <= 0) { return res.status(400).json({ error: 'printerId must be an integer' }); } @@ -387,16 +389,21 @@ export function register(app, basePath = '') { return res.status(400).json({ error: 'quantity must be an integer' }); } - const parsedPrinterId = { id: printerId }; + const parsedPrinterId = { id: rawPrinterId }; const parsedTemplateId = { id: templateId }; const parsedQuantity = { id: quantity }; try { - const printer = await printerDb.getById(req.user.id, parsedPrinterId.id); + let printer = await printerDb.getById(req.user.id, parsedPrinterId.id); if (!printer || printer.company_id !== companyId) { - return res.status(404).json({ error: 'Printer not found' }); + const agentPrinter = await agentprinterDb.getById(req.user.id, parsedPrinterId.id); + if (agentPrinter) { + printer = agentPrinter; + } else { + return res.status(404).json({ error: 'Printer not found' }); + } } - if (printer.type !== 'zpl') { + if (printer.type && printer.type.toLowerCase() !== 'zpl') { return res.status(400).json({ error: 'Printer is not a ZPL printer' }); } @@ -444,7 +451,8 @@ export function register(app, basePath = '') { }); // Mock network dispatch - const printDir = path.join(process.cwd(), 'print_spool', `${printer.address}_${printer.type}`); + const spoolKey = printer.address ? `${printer.address}_${printer.type}` : `agent_${printer.id}_${printer.type || 'zpl'}`; + const printDir = path.join(process.cwd(), 'print_spool', spoolKey); await fs.mkdir(printDir, { recursive: true }); for (let i = 0; i < parsedQuantity.id; i++) {