Add README.md

Add windows support
This commit is contained in:
René Preuß
2024-01-21 16:07:29 +01:00
parent 2a92c22bec
commit e60f6ec846
4 changed files with 95 additions and 348 deletions

View File

@@ -1,4 +1,4 @@
import {getPrinters, print} from "unix-print";
import { getPrinters, print } from './print.js'
import express from 'express'
import cors from 'cors'
@@ -8,11 +8,11 @@ import multer from 'multer'
const app = express()
const port = 1903
const upload = multer({dest: 'uploads/'})
const upload = multer({ dest: 'uploads/' })
app.use(cors())
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.get('/', (req, res) => {
res.send('Hello World!')
@@ -24,21 +24,21 @@ app.get('/printers', async (req, res) => {
return {
default: false,
format: 'PDF',
id: printer.printer,
name: printer.printer,
id: printer.printer || printer.deviceId,
name: printer.printer || printer.name,
}
}))
})
app.post('/printers/:printer/print', upload.single('file'), async (req, res) => {
const {printer} = req.params
const { printer } = req.params
// query: user-id: string, docType: label
// form data: file: binary, copies: string, shipment-ids: string
const fileToPrint = req.file.path;
const printJob = await print(fileToPrint, printer);
const jobId = getRequestId(printJob);
const fileToPrint = req.file.path
const printJob = await print(fileToPrint, printer)
const jobId = getRequestId(printJob)
return res.json({
jobs: [jobId],
@@ -51,6 +51,10 @@ app.listen(port, () => {
})
function getRequestId(printJob) {
if (printJob === undefined) {
return '0'
}
const requestId = printJob.stdout.split(' ')[3]
return requestId.split('-')[1]
}