diff --git a/server/scripts/print-image.ts b/server/scripts/print-image.ts new file mode 100644 index 0000000..0f85ed0 --- /dev/null +++ b/server/scripts/print-image.ts @@ -0,0 +1,35 @@ +import { Image, Printer } from "@node-escpos/core"; +import USB from "@node-escpos/usb-adapter"; +import { join } from "path"; + +async function printImage(path: string) { + const device = new USB(); + await new Promise((resolve,reject) => { + device.open(async function(err){ + if(err){ + reject(err); + return + } + + let printer = new Printer(device, {}); + + const tux = path; // join(__dirname, '../assets/tux.png'); + const image = await Image.load(tux); + + // inject image to printer + printer = await printer.image(image, "d24") + + printer + .cut() + .close() + .finally(resolve) + }); + }); +} + +console.log(process.argv); + +printImage(process.argv[2] || join(__dirname, 'tux.png')) + .then(() => console.log('done')) + .catch((err) => console.error(err)); + diff --git a/server/scripts/tux.png b/server/scripts/tux.png new file mode 100644 index 0000000..e32f8d9 Binary files /dev/null and b/server/scripts/tux.png differ diff --git a/server/src/db/repositories/step-repository.ts b/server/src/db/repositories/step-repository.ts index 314b094..5732796 100644 --- a/server/src/db/repositories/step-repository.ts +++ b/server/src/db/repositories/step-repository.ts @@ -14,11 +14,11 @@ export class StepRepository extends BaseRepository { .orderBy('order') .select('*'); - logger.info(`Retrieved ${steps.length} steps for task ${taskId}`); + /*logger.info(`Retrieved ${steps.length} steps for task ${taskId}`); for (const step of steps) { logger.info(`Step ${step.id}: name="${step.name}", instructions="${step.instructions}"`); logger.info(`Full step data:`, JSON.stringify(step, null, 2)); - } + }*/ return steps; } @@ -63,4 +63,4 @@ export class StepRepository extends BaseRepository { return steps.findIndex(s => s.id === stepId) + 1; } -} \ No newline at end of file +} diff --git a/server/src/index.ts b/server/src/index.ts index 3a13ac2..975bf5c 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -60,13 +60,14 @@ async function startServer() { // YAML Import endpoint app.post('/api/yaml/import', async (req, res) => { try { - const { yamlContent } = req.body; + const yamlContent = req.body; + console.log('loading YAML:', yamlContent); - if (!yamlContent || typeof yamlContent !== 'string') { + if (!yamlContent || typeof yamlContent !== 'object') { return res.status(400).json({ error: 'YAML content is required' }); } - await yamlService.importFromYaml(yamlContent); + await yamlService.importFromYaml(JSON.stringify(yamlContent)); res.json({ message: 'Database imported successfully' }); } catch (error) { logger.error('Error importing YAML:', error); @@ -101,4 +102,4 @@ async function startServer() { startServer().catch((error) => { logger.error('Failed to start server:', error); process.exit(1); -}); \ No newline at end of file +}); diff --git a/server/src/printer/command-executor.ts b/server/src/printer/command-executor.ts index 5a1fefe..431a46e 100644 --- a/server/src/printer/command-executor.ts +++ b/server/src/printer/command-executor.ts @@ -126,7 +126,9 @@ export class SerialCommandExecutor implements CommandExecutor { break; case Command.CHECKBOX: - await this.printer.text(formatUtils.getCheckboxText(formatUtils.checkbox(params[0] as string))); + const text = params[0] as string; + const checkbox = `[ ] ${text}`; + await this.printer.text(checkbox); break; case Command.LIST: diff --git a/server/src/printer/serial-printer.ts b/server/src/printer/serial-printer.ts index 7c2d9bf..d70ed82 100644 --- a/server/src/printer/serial-printer.ts +++ b/server/src/printer/serial-printer.ts @@ -5,7 +5,7 @@ import { StepRepository, PrintHistoryRepository } from '../db/repositories'; import { Knex } from 'knex'; import logger from '../logger'; import { formatUtils } from './format-utils'; -import { CommandBuilder } from './printer-commands'; +import { Command, CommandBuilder } from './printer-commands'; import { SerialCommandExecutor } from './command-executor'; import { PRINTER_CONFIG, @@ -111,17 +111,15 @@ export class SerialPrinter implements PrinterInterface { const step = taskSteps[i]; logger.info(`Printing step ${step.id}: name="${step.name}", instructions="${step.instructions}"`); - const headerText = formatUtils.getCheckboxText(formatUtils.stepHeader(step.name, i + 1, task.name, true)); commands.push( CommandBuilder.fontSize(FONT_SIZES.NORMAL), - CommandBuilder.text(headerText), - ...formatUtils.section( - '', + formatUtils.stepHeader(step.name, i + 1, task.name, true), + CommandBuilder.banner('-', PAPER_CONFIG.BANNER_LENGTH), + CommandBuilder.text( step.instructions || 'No instructions provided', - '-' ), CommandBuilder.newline(), - ...CommandBuilder.stepBarcodeWithAlignment(step.id), + // ...CommandBuilder.stepBarcodeWithAlignment(step.id), CommandBuilder.newline() ); } @@ -170,7 +168,8 @@ export class SerialPrinter implements PrinterInterface { CommandBuilder.align(ALIGNMENT.CENTER), CommandBuilder.style(STYLE.BOLD), CommandBuilder.fontSize(FONT_SIZES.NORMAL), - CommandBuilder.text(headerText), + formatUtils.stepHeader(step.name, stepNumber, task?.name), + // CommandBuilder.text(headerText), CommandBuilder.newline(), CommandBuilder.align(ALIGNMENT.LEFT), CommandBuilder.fontSize(FONT_SIZES.NORMAL),