changes
This commit is contained in:
20
server/api/print/barcode.post.ts
Normal file
20
server/api/print/barcode.post.ts
Normal 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) });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user