21 lines
661 B
TypeScript
21 lines
661 B
TypeScript
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) });
|
|
}
|
|
});
|