This commit is contained in:
Viet An
2026-06-25 09:52:06 +07:00
parent 61fc829a91
commit 9f0729ccd9
5 changed files with 78 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
import { execFile } from "child_process";
import { promisify } from "util";
import path from "path";
const execFileAsync = promisify(execFile);
export default defineEventHandler(async (event) => {
const body = await readBody(event);
const { name, imei, price } = body;
const scriptPath = path.join(process.cwd(), "print", "print_barcode.py");
const payload = JSON.stringify({ name, imei, price });
try {
const { stdout } = await execFileAsync("python", [scriptPath, payload]);
return { success: true, output: stdout };
} catch (err) {
throw createError({ statusCode: 500, statusMessage: "Print failed", data: String(err) });
}
});