Add fake printer

This commit is contained in:
René Preuß
2024-03-06 10:05:25 +01:00
parent ef4bb777f2
commit 07285b6dab

View File

@@ -10,6 +10,12 @@ const port = 1903
const upload = multer({ dest: 'uploads/' })
const debug = process.argv.includes('--debug')
if (debug) {
console.log('Running in debug mode')
}
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
@@ -19,10 +25,20 @@ app.get('/', (req, res) => {
})
app.get('/printers', async (req, res) => {
const printerList = []
if (debug) {
printerList.push({
default: false,
format: 'PDF',
id: 'Fake Printer',
name: 'Fake Printer',
})
}
try {
const printers = await getPrinters()
return res.json(printers.map(printer => {
printerList.push(...printers.map(printer => {
return {
default: false,
format: 'PDF',
@@ -32,8 +48,9 @@ app.get('/printers', async (req, res) => {
}))
} catch (e) {
console.error('Error getting printers', e)
return res.json([])
}
return res.json(printerList)
})
app.post('/printers/:printer/print', upload.single('file'), async (req, res) => {
@@ -42,6 +59,12 @@ app.post('/printers/:printer/print', upload.single('file'), async (req, res) =>
// query: user-id: string, docType: label
// form data: file: binary, copies: string, shipment-ids: string
if (printer === 'Fake Printer') {
return res.json({
jobs: ['0'],
})
}
try {
const fileToPrint = req.file.path
const printJob = await print(fileToPrint, printer)