improve printer format, reduce some logs

This commit is contained in:
Sean Sube 2025-06-18 20:31:10 -05:00
parent 7d680e469f
commit 02d4bae997
No known key found for this signature in database
GPG Key ID: 3EED7B957D362AF1
6 changed files with 53 additions and 16 deletions

View File

@ -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<void>((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));

BIN
server/scripts/tux.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -14,11 +14,11 @@ export class StepRepository extends BaseRepository<Step> {
.orderBy('order') .orderBy('order')
.select('*'); .select('*');
logger.info(`Retrieved ${steps.length} steps for task ${taskId}`); /*logger.info(`Retrieved ${steps.length} steps for task ${taskId}`);
for (const step of steps) { for (const step of steps) {
logger.info(`Step ${step.id}: name="${step.name}", instructions="${step.instructions}"`); logger.info(`Step ${step.id}: name="${step.name}", instructions="${step.instructions}"`);
logger.info(`Full step data:`, JSON.stringify(step, null, 2)); logger.info(`Full step data:`, JSON.stringify(step, null, 2));
} }*/
return steps; return steps;
} }
@ -63,4 +63,4 @@ export class StepRepository extends BaseRepository<Step> {
return steps.findIndex(s => s.id === stepId) + 1; return steps.findIndex(s => s.id === stepId) + 1;
} }
} }

View File

@ -60,13 +60,14 @@ async function startServer() {
// YAML Import endpoint // YAML Import endpoint
app.post('/api/yaml/import', async (req, res) => { app.post('/api/yaml/import', async (req, res) => {
try { 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' }); 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' }); res.json({ message: 'Database imported successfully' });
} catch (error) { } catch (error) {
logger.error('Error importing YAML:', error); logger.error('Error importing YAML:', error);
@ -101,4 +102,4 @@ async function startServer() {
startServer().catch((error) => { startServer().catch((error) => {
logger.error('Failed to start server:', error); logger.error('Failed to start server:', error);
process.exit(1); process.exit(1);
}); });

View File

@ -126,7 +126,9 @@ export class SerialCommandExecutor implements CommandExecutor {
break; break;
case Command.CHECKBOX: 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; break;
case Command.LIST: case Command.LIST:

View File

@ -5,7 +5,7 @@ import { StepRepository, PrintHistoryRepository } from '../db/repositories';
import { Knex } from 'knex'; import { Knex } from 'knex';
import logger from '../logger'; import logger from '../logger';
import { formatUtils } from './format-utils'; import { formatUtils } from './format-utils';
import { CommandBuilder } from './printer-commands'; import { Command, CommandBuilder } from './printer-commands';
import { SerialCommandExecutor } from './command-executor'; import { SerialCommandExecutor } from './command-executor';
import { import {
PRINTER_CONFIG, PRINTER_CONFIG,
@ -111,17 +111,15 @@ export class SerialPrinter implements PrinterInterface {
const step = taskSteps[i]; const step = taskSteps[i];
logger.info(`Printing step ${step.id}: name="${step.name}", instructions="${step.instructions}"`); 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( commands.push(
CommandBuilder.fontSize(FONT_SIZES.NORMAL), CommandBuilder.fontSize(FONT_SIZES.NORMAL),
CommandBuilder.text(headerText), formatUtils.stepHeader(step.name, i + 1, task.name, true),
...formatUtils.section( CommandBuilder.banner('-', PAPER_CONFIG.BANNER_LENGTH),
'', CommandBuilder.text(
step.instructions || 'No instructions provided', step.instructions || 'No instructions provided',
'-'
), ),
CommandBuilder.newline(), CommandBuilder.newline(),
...CommandBuilder.stepBarcodeWithAlignment(step.id), // ...CommandBuilder.stepBarcodeWithAlignment(step.id),
CommandBuilder.newline() CommandBuilder.newline()
); );
} }
@ -170,7 +168,8 @@ export class SerialPrinter implements PrinterInterface {
CommandBuilder.align(ALIGNMENT.CENTER), CommandBuilder.align(ALIGNMENT.CENTER),
CommandBuilder.style(STYLE.BOLD), CommandBuilder.style(STYLE.BOLD),
CommandBuilder.fontSize(FONT_SIZES.NORMAL), CommandBuilder.fontSize(FONT_SIZES.NORMAL),
CommandBuilder.text(headerText), formatUtils.stepHeader(step.name, stepNumber, task?.name),
// CommandBuilder.text(headerText),
CommandBuilder.newline(), CommandBuilder.newline(),
CommandBuilder.align(ALIGNMENT.LEFT), CommandBuilder.align(ALIGNMENT.LEFT),
CommandBuilder.fontSize(FONT_SIZES.NORMAL), CommandBuilder.fontSize(FONT_SIZES.NORMAL),